1020. Rope

来源:互联网 发布:neflix 淘宝账号 编辑:程序博客网 时间:2024/06/06 03:54
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;
}
原创粉丝点击