pku 2365 Rope 解题报告
2010-05-22 19:24
423 查看
Rope
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
Sample Output
Source
Ural State University Internal Contest October'2000 Junior Session
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3084 | Accepted: 1139 |
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
/** 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; }
相关文章推荐
- poj解题报告——poj 2365 Rope
- pku 3753 根据关键字进行字符串拷贝 解题报告
- Flip and Shift -- ACM PKU 1063 解题报告
- pku_1256 Anagram 解题报告
- pku 1970 搜索 The Game 解题报告
- pku_1862 Stripies 解题报告
- pku 1111 解题报告 简单的广度优先搜索
- Pku acm 1961 Period数据结构题目解题报告(十九)----kmp算法
- PKU 2366 Wireless Network (解题报告)
- pku 3621 01分数规划 sightseeing cows 解题报告
- pku 1947 Rebuilding Roads 树形dp 解题报告
- pku 1185 炮兵阵地 压缩dp 解题报告
- pku 1011 sticks 搜索+剪枝 解题报告
- pku 1466 Girls and Boys 最大独立集 解题报告
- PKU Campus 2015解题报告
- ACM pku 1003 解题报告(练习输入输出)
- Pku acm 1080 Humman Gene Function 动态规划题目解题报告(八)
- Pku acm 1088 滑雪 动态规划题目解题报告(十五)
- Pku acm 1125 Stockbroker Grapevine 动态规划题目解题报告(十九)
- Pku acm 1611 The Suspects数据结构题目解题报告(九)---- 并查集的应用