(AtCoder Beginner Contest 375)B - Traveling Takahashi Problem

题目大意
按顺序给定n个点  
     
      
       
       
         ( 
        
        
        
          x 
         
        
          i 
         
        
       
         , 
        
        
        
          y 
         
        
          i 
         
        
       
         ) 
        
       
      
        (x_i,y_i) 
       
      
    (xi,yi)
 求按顺序走过这n个点并回到原点的总距离
 任意两点之间的距离是欧几里得距离
思路
按照题意模拟即可,时间复杂度 O ( n ) O(n) O(n)
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#define rep(i,x,y) for(ll i=x;i<=y;++i)
#define per(i,x,y) for(ll i=x;i>=y;--i)
using namespace std;
typedef long long ll;
ll n,x,y,u,v;
double ans;
inline ll in()
{
    ll res=0,f=1;
    char ch;
    while((ch=getchar())<'0'||ch>'9')
     if(ch=='-') f=-1;
    res=res*10+ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
     res=res*10+ch-'0';
    return res*f;
}
inline void put(ll x)
{
    if(x<0) putchar('-'),x*=-1;
    if(x>9) put(x/10);
    putchar(x%10+48);
}
double dis(ll x,ll y)
{
	double res=sqrt(x*x+y*y);
	return res;
}
int main()
{
	n=in();
	rep(i,1,n)
	{
		u=in(),v=in();
		ans+=dis(u-x,v-y);
		x=u,y=v;
	}
	ans+=dis(u,v);
	printf("%.9lf",ans);
    return 0;
}
                


















