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

迷茫时就切两道--借用

时间:2014-11-27 23:36:39      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   sp   for   div   log   

背景
平面上有N个圆柱形的大钉子,半径都为R,所有钉子组成一个凸多边形。
现在你要用一条绳子把这些钉子围起来,绳子直径忽略不计。
描述
求出绳子的长度
格式
输入格式
第1行两个数:整数N(1<=N<=100)和实数R。
接下来N行按逆时针顺序给出N个钉子中心的坐标
坐标的绝对值不超过100。
输出格式
一个数,绳子的长度,精确到小数点后2位。
样例1
样例输入1[复制]
4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0
样例输出1[复制]
14.28
限制
各个测试点1s

 

#include<iostream>
#include<stdio.h>
#include<math.h>
#define p 3.1415926
using namespace std;
class Length
{
    public:
    float x;
    float y;

};
int  Len(Length &a,Length &b)
{
    return (sqrt(pow((a.x-b.x),2)+pow((a.y-b.y),2)));
}

int main()
{
    float s=0;
    int N,R;
    int i;
    Length now,last,first;
    cin>>N>>R;
    cin>>first.x>>first.y;
    last.x=first.x;
    last.y=first.y;
    for(i=1;i<N;i++)
    {
    cin>>now.x>>now.y;
    s=s+Len(now,last);
    last.x=now.x;
    last.y=now.y;

    }
    s=s+Len(now,first)+2*p*R;
    printf("%.2f",s);
    return 0;

}

 

迷茫时就切两道--借用

标签:style   blog   io   color   os   sp   for   div   log   

原文地址:http://www.cnblogs.com/yaobolove/p/4127377.html

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