码迷,mamicode.com
首页 > 其他好文 > 详细

回档|绕钉子的长绳子

时间:2015-04-05 08:59:38      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:

背景 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; 
} 

 

 

回档|绕钉子的长绳子

标签:

原文地址:http://www.cnblogs.com/Shymuel/p/4393557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!