pku 2365 Rope 解题报告

 

Rope
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3084   Accepted: 1139

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. 
pku 2365 Rope 解题报告_第1张图片 
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
/** http://acm.pku.edu.cn/JudgeOnline/problem?id=2365 */ /** 解题思路: 这道题是典型的计算几何。公式其实很简单:各个圆的圆心距离之和+一个圆的周长 这个题数据有点问题,居然是按照顺行给的,不然就要按照极角排序,进行处理。 */ #include <iostream> #include <cmath> #include <algorithm> #define PI acos(-1.0) using namespace std; struct Point { double x; double y; }; Point p[105]; double r; int n; double mult(Point p1,Point p2,Point p0) { return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y); } double dist(Point a,Point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } int compare1(Point a, Point b) { if (a.y < b.y) return 1; else if(a.y == b.y) { return a.x < b.y; } else { return 0; } } int compare2(Point a,Point b) { if( mult(a,b,p[0])>0 ) return 1; else { if(mult(a,b,p[0])==0&&dist(a,p[0])<dist(b,p[0])) return 1; else return 0; } } double length() { sort(p, p + n, compare1); sort(p + 1, p + n, compare2); double sum = 0.0; int i; for(i = 1; i < n; i++) { sum += dist(p[i-1], p[i]); } sum += dist(p[n-1], p[0]); sum += 2 * PI * r; return sum; } void input() { int i; for(i = 0; i < n; i++) { cin >> p[i].x >> p[i].y; } } int main() { // freopen("2365.in","r",stdin); while(cin >> n >> r) { input(); double l = length(); printf("%.2lf/n",l); } return 0; } 

 

你可能感兴趣的:(object,input,each,output,pair,Numbers)