POJ 1113 Wall
来源:互联网 发布:4s移动3g网络设置方法 编辑:程序博客网 时间:2024/05/01 02:35
Wall
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 24787 Accepted: 8256
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
结果四舍五入就可以了
Source
Northeastern Europe 2001
注意四舍五入啊
#include <stdio.h>#include <string.h>#include <math.h>#define PI 3.1415927struct map{ int x,y;}a[1100];struct num{ int x,y;}statck[1100];int chacheng(int x1,int y1,int x2,int y2){ int t=x1*y2-y1*x2; if(t>0) { return 1; }else if(t<0) { return -1; }else { return 0; }}int cmp(const void *e,const void *f){ int x1,y1,x2,y2,t; struct map *p1=(struct map *)e; struct map *p2=(struct map *)f; x1=p1->x-a[0].x; y1=p1->y-a[0].y; x2=p2->x-a[0].x; y2=p2->y-a[0].y; t=chacheng(x1,y1,x2,y2); if(t==1) { return -1; }else if(t==-1) { return 1; }else { return (x1*x1+y1*y1)-(x2*x2+y2*y2); }}int main(){ int i,j,n,m,s,t,r,pos,top,truedis; int x1,y1,x2,y2; double dis; while(scanf("%d %d",&n,&r)!=EOF) { for(i=0;i<=n-1;i++) { scanf("%d %d",&a[i].x,&a[i].y); if(i==0) { pos=i; }else { if((a[i].y<a[pos].y)||(a[i].y==a[pos].y&&a[i].x<a[pos].x)) { pos=i; } } } t=a[0].x; a[0].x=a[pos].x; a[pos].x=t; t=a[0].y; a[0].y=a[pos].y; a[pos].y=t; qsort(a+1,n-1,sizeof(a[0]),cmp); statck[0].x=a[0].x; statck[0].y=a[0].y; statck[1].x=a[1].x; statck[1].y=a[1].y; for(i=2,top=2;i<=n-1;) { if(top>=2) { x1=statck[top-1].x-statck[top-2].x; y1=statck[top-1].y-statck[top-2].y; x2=a[i].x-statck[top-1].x; y2=a[i].y-statck[top-1].y; t=chacheng(x1,y1,x2,y2); if(t>0||t==0) { statck[top].x=a[i].x; statck[top].y=a[i].y; top++; i++; }else { top--; } }else { statck[top].x=a[i].x; statck[top].y=a[i].y; top++; } } dis=0; dis+=2*PI*(double)r; for(i=1;i<=top-1;i++) { x1=statck[i].x-statck[i-1].x; y1=statck[i].y-statck[i-1].y; dis+=sqrt((double)(x1*x1+y1*y1)); } x1=statck[top-1].x-statck[0].x; y1=statck[top-1].y-statck[0].y; dis+=sqrt((double)(x1*x1+y1*y1)); truedis=(int)(dis+0.01); dis=dis-truedis; if(fabs(dis-0.50)<=1e-7||dis-0.50>0) { truedis++; } printf("%d\n",truedis); } return 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
- 将类给实例化
- 正则表达式的数字实例
- 三星新推出Tizen操作系统初体验
- 工作感悟
- unity3d中javasciprt脚本参考
- POJ 1113 Wall
- .....................
- Asynchronous image loading is easy with AQuery.
- 代码整洁之道------命名
- FreeBSD 9.1内核kernel文件和模块文件
- FreeBSD 9.1用kgdb调试kernel dump文件
- Android4.0以上源码中的DiskLruCache类简介
- FreeBSD 9.1使用DDB在线调试内核
- FreeBSD 9.1内核的参数描述文件