回档|绕钉子的长绳子

背景 Background

平面上有N个圆柱形的大钉子,半径都为R,所有钉子组成一个凸多边形。
现在你要用一条绳子把这些钉子围起来,绳子直径忽略不计。

描述 Description

求出绳子的长度

输入格式 Input Format

第1行两个数:整数N(1<=N<=100)和实数R。
接下来N行按逆时针顺序给出N个钉子中心的坐标
坐标的绝对值不超过100。

 

输出格式 Output Format

一个数,绳子的长度,精确到小数点后2位。

输入样例:

4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0

输出样例:

14.28

 

题目分析:

    这么水的题我一般不会发的(那你做什么?),但这道题我竟然wa了一个点。我很不解……

#include<iostream>
#include<cstdio>
#include<cstring>
#define pi 3.141592653
int main() 
{ 
    double Circum,R,x0,y0,x1,y1,x,y; 
    int n,i; 
    scanf("%d %lf",&n,&R); 
    scanf("%lf %lf",&x0,&y0); 
 
    x1 = x0; 
    y1 = y0; 
    for (i=1; i
    { 
        scanf("%lf %lf",&x,&y); 
        Circum+=hypot(x-x1,y-y1); 
        x1 = x; 
        y1 = y; 
    } 
    Circum+=hypot(x-x0,y-y0); 
    Circum+=pi*2*R; 
    printf("%.2lf",Circum);
    return 0; 
} 

 

 

posted @ 2015-04-05 08:04  竹夭公子  阅读(157)  评论(0编辑  收藏  举报