水题,没什么好说的,注意N=1的情况.
1 #include<iostream>
2 #include<math.h>
3 using namespace std;
4 const double PI=3.1415926;
5
6 template <class T>
7 T dis(T x1,T y1,T x2,T y2)
8 {
9 return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
10 }
11 int main()
12 {
13 int n;
14 double r,len=0;
15 //freopen("data.in","r",stdin);
16 //freopen("data.out","w",stdout);
17 cin >> n >> r;
18 double x0,y0,x,y;
19 cin >> x0 >> y0;
20 double px=x0,py=y0;
21 if (n==1) goto L1;
22 for (int i=1;i<n;++i)
23 {
24 cin >> x >> y;
25 len+=dis(px,py,x,y);
26 px=x;
27 py=y;
28 }
29 len+=dis(x,y,x0,y0);
30 L1: len+= 2*PI*r ;
31 printf("%.2f\n",len);
32 return 0;
33 }
34