2365 Rope

来源:互联网 发布:php中使用url传递数组 编辑:程序博客网 时间:2024/05/17 10:25

Description

Plotters have barberically 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.
这里写图片描述
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 in a clockwise order starting from an arbitrary nail. Heads of different nails don’t adjoin.

Output

The standard output should contain in its only line 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

Sample Output

14.28

Source

Ural State University Internal Contest October’2000 Junior Session


/*绳子长度等于N个圆心距离和加上钉子周长*/#include<iostream>#include<iomanip>#include<math.h>using namespace std;#define PI 3.1415926535898struct nail {    double x, y;}coor[100];int main(){    int N;    double R, length = 0;    cin >> N >> R;    for (int i = 0; i < N; i++)    {        cin >> coor[i].x >> coor[i].y;    }    for (int i = 0; i < N - 1; i++)    {        length += sqrt((coor[i + 1].x - coor[i].x)*(coor[i + 1].x - coor[i].x) + (coor[i + 1].y - coor[i].y)*(coor[i + 1].y - coor[i].y));    }    length += sqrt((coor[0].x - coor[N - 1].x)*(coor[0].x - coor[N - 1].x) + (coor[0].y - coor[N - 1].y)*(coor[0].y - coor[N - 1].y));    length += 2*R*PI;    cout << fixed << setprecision(2) << length << endl;    return 0;}
原创粉丝点击