您的位置:首页 > 运维架构

1020. Rope

2017-10-10 19:26 597 查看
1020. Rope

Time limit: 1.0 second

Memory limit: 64 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 overlap.

Output

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

Sample

input

4 1

0.0 0.0

2.0 0.0

2.0 2.0

0.0 2.0

output

14.28

#include<iostream>

#include <math.h>

using namespace std;

float a[105][2];

int main(){

    int pointnum ;

    int r ;

    cin>>pointnum;

    cin>>r;

    double rope = 0;

    for(int i = 0 ; i < pointnum ; i++){

        cin>>a[i][0];

        cin>>a[i][1];

    }

    for(int i = 0 ; i < pointnum+1 ; i++){

        if(i==pointnum){

            int t = (a[0][0]-a[i][0])*(a[0][0]-a[i][0]) + (a[0][1]-a[i][1])*(a[0][1]-a[i][1]);

            rope = rope + sqrt(abs(t));

        }

        else{

            int t = (a[i+1][0]-a[i][0])*(a[i+1][0]-a[i][0]) + (a[i+1][1]-a[i][1])*(a[i+1][1]-a[i][1]);

            rope = rope + sqrt(abs(t));

        }

    }

    rope = rope + 3.14 * 2 * r;

    cout<<rope;

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: