POJ-1113-Wall
来源:互联网 发布:下载微客多软件 编辑:程序博客网 时间:2024/06/07 03:20
Wall
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 34862 Accepted: 11885
Description
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall.
Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.
The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.
The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
Input
The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle.
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
Output
Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.
Sample Input
9 100200 400300 400300 300400 300400 400500 400500 200350 200200 200
Sample Output
1628
Hint
结果四舍五入就可以了
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;struct node{ int x; int y;} point[100000];int n;int s[100000], top;double chacheng(struct node a, struct node b, struct node c){ return ((a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x));}double dist(struct node a, struct node b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}bool cmp(struct node a,struct node b){ int k=chacheng(a,b,point[0]); if(k>0) return 1; else if(k==0&&dist(a,point[0])<dist(b,point[0])) return 1; else return 0;}void Graham(){ int k=0; int i; for(i=1; i<n; i++) { if (point[i].x<point[k].x||(point[i].x==point[k].x&&point[i].y<point[k].y)) { k=i; } } swap(point[0],point[k]); sort(point,point+n,cmp); for(i=0; i<=2; i++) { s[i]=i; } top=2; for(i=3; i<n; i++) { while(chacheng(point[i],point[s[top]],point[s[top-1]])>=0) { top--; if(top==0) { break; } } top++; s[top]=i; }}double dis(node a, node b){ int x = a.x-b.x, y = a.y-b.y; return 1.0*sqrt(x*x+y*y);}int main(){ int l; while(~scanf("%d%d",&n, &l)) { for(int i=0; i<n; i++) scanf("%d%d",&point[i].x,&point[i].y); Graham(); double sum = 0.0; for(int i = 0; i<top; ++i) { sum+=dis(point[s[i]], point[s[i+1]]); } sum+=dis(point[s[0]], point[s[top]]); sum+=2*3.1415926*l; printf("%.0f\n", sum); } return 0;}
0 0
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 wall
- poj 1113 Wall
- POJ 1113 wall
- poj 1113 Wall
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113(Wall-Quickhull)
- POJ 1113 Wall
- poj-1113-Wall
- poj 1113 Wall
- POJ 1113 Wall
- POJ 1113 Wall
- poj - 1113 - Wall
- eclipse关于项目validate的过滤选择
- linux3.4版本内核make出现的错误----缺少compiler-gcc5.h
- fastboot 源码分析2
- HDU 1592 Half of and a Half(高精度)
- oracle字符窜操作
- POJ-1113-Wall
- linux shell 获取当前正在执行脚本的绝对路径
- PAT 1008
- 百度地图API示范例
- jquery ajax error 200 解决方案
- 数据结构实验之链表四:有序链表的归并
- 哪些情况下索引会失效?
- "=="、equals和hashCode的区别
- C++ 运算符重载