Ural 1020 Rope

1020. Rope

Time Limit: 1.0 second
Memory Limit: 16 MB
Plotters have barbarously hammered N nails into an innocent plane shape, so that one can see now only heads. Moreover, pursuing their mean object, they have hammered all the nails into the vertices of a convex polygon. After that they…it is awful… have roped off the nails, so that the shape felt upset (the rope was very thin). They’ve done it as it is shown in the figure.
Problem illustration
Your task is to find out a length of the rope.

Input

There two numbers in the first line of the standard input: N — a number of nails (1 ≤ N ≤ 100), and a real number R — a radius of heads of nails. All the heads have the same radius. Further there are N lines, each of them contains a pair of real coordinates (separated by a space) of centers of nails. An absolute value of the coordinates doesn’t exceed 100. The nails are described either in a clockwise or in a counterclockwise order starting from an arbitrary nail. Heads of different nails don’t adjoin.

Output

Output a real number with two digits precision (after a decimal point) — a length of the rope.

Sample

input output
4 1
                        0.0 0.0
                        2.0 0.0
                        2.0 2.0
                        0.0 2.0
                        
14.28
                        
Problem Author: Alexander Petrov & Nikita Shamgunov
Problem Source: Ural State University Internal Contest October'2000 Junior Session

结果就是各线段长度的和加上半径为R的周长,n=1时 需额外考虑下
#include<iostream>
#include
<stdio.h>
#include
<cmath>
using namespace std;
double const  pi=acos(-1.0);
int main()
{
    
int n=0,i=0;
    
double sum=0,r=0,x0,y0,x1,y1,x,y;
    
    cin
>>n>>r;
    cin
>>x>>y;// 保存第一个点  
    
    x0
=x1=x; y0=y1=y;
    sum
=2*pi*r;
    
for(i=1; i<n; i++)
    {
             cin
>>x1>>y1;
             sum
+=sqrt( (x1-x0)*(x1-x0)+ (y1-y0)*(y1-y0) );
             x0
=x1; y0=y1;
    }
    
if(n!=1) sum+=sqrt( (x1-x)*(x1-x)+ (y1-y)*(y1-y) );
    
    printf(
"%.2lf\n",sum);
    system(
"pause");
    
return 0;
}

posted on 2010-06-22 17:05 田兵 阅读(317) 评论(0)  编辑 收藏 引用 所属分类: URAL


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年6月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

导航

统计

常用链接

留言簿(2)

随笔分类(65)

随笔档案(65)

文章档案(2)

ACM

搜索

积分与排名

最新随笔

最新评论

阅读排行榜