ural 1020 Rope

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <algorithm>
 5 #define maxn 2000
 6 using namespace std;
 7 const double pi=acos(-1.0);
 8 
 9 double sqr(double x)
10 {
11     return x*x;
12 }
13 struct node
14 {
15     double x,y;
16 }p[maxn];
17 
18 double dis(node a,node b)
19 {
20     return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
21 }
22 int main()
23 {
24     int n;
25     double r;
26     scanf("%d%lf",&n,&r);
27     for(int i=0; i<n; i++)
28     {
29         scanf("%lf%lf",&p[i].x,&p[i].y);
30     }
31     p[n]=p[0];
32     double ans=0;
33     for(int i=1; i<=n; i++)
34     {
35         ans+=dis(p[i],p[i-1]);
36     }
37     ans+=pi*r*2;
38     printf("%.2lf
",ans);
39     return 0;
40 }
View Code
原文地址:https://www.cnblogs.com/fanminghui/p/3604832.html