hdu 1348 Wall(凸包模板)
来源:互联网 发布:qq音乐for mac 10.7.5 编辑:程序博客网 时间:2024/04/30 02:56
Wall
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2350 Accepted Submission(s): 647
Problem 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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Sample Input
19 100200 400300 400300 300400 300400 400500 400500 200350 200200 200
Sample Output
1628
Source
Northeastern Europe 2001
Recommend
JGShining
题意:求凸包的边长
题解:照着模板敲的...留作以后看模板用
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#define PI 3.14159265#define inf 0.000001struct point{ double x,y;}p[1005],res[1005];int n;double mult(struct point p1,struct point p2,struct point p3){ return (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x);}double dis(struct point a,struct point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int cmp(const void *a,const void *b){ struct point c=*(struct point *)a; struct point d=*(struct point *)b; double k=mult(p[0],c,d); if(k<0||(!k&&dis(c,p[0])>dis(d,p[0]))) return 1; return -1;}int convex(){ int i,top=1; struct point temp; for(i=1;i<n;i++) { if(p[i].y<p[0].y||(p[i].y==p[0].y&&p[i].x<p[0].x)) temp=p[i],p[i]=p[0],p[0]=temp; } qsort(p+1,n-1,sizeof(p[0]),cmp); res[0]=p[0],res[1]=p[1]; for(i=2;i<n;i++) { while(top>=1&&mult(res[top-1],res[top],p[i])<=0) top--; res[++top]=p[i]; } return top;}int main(){ double r,sum; int i,t,top; scanf("%d",&t); while(t--) { scanf("%d%lf",&n,&r); for(i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y); top=convex(); for(sum=i=0;i<top;i++) sum+=dis(res[i],res[i+1]); sum+=dis(res[top],res[0]); sum+=2*PI*r; printf("%.0lf\n",sum); if(t) printf("\n"); } return 0;}
- hdu 1348 Wall(凸包模板)
- hdu 1348 Wall 凸包模板题
- hdu 1348 Wall (凸包模板)
- hdu 1348 Wall (凸包模板)
- hdu 1348 Wall(凸包模板题 Graham)
- HDU 1348 Wall(凸包模板题)
- HDU-1348 Wall 凸包
- Hdu 1348 Wall 凸包
- hdu-1348 Wall(凸包)
- HDU Wall(凸包)
- 凸包模板 Wall
- HDOJ 1348 Wall (凸包模板题)
- POJ 1113 wall(凸包模板)
- hdu1348 Wall(凸包模板题)
- POJ 1113 || HDU 1348: wall(凸包问题)
- hdu 1348 wall (计算几何,凸包)
- POJ 1113 && HDU 1348 Wall(凸包)
- HDU 1348 && POJ 1113 Wall(凸包)
- win7 x64环境下用vc2008编译mysql++注意事项
- (转)让Android模拟器飞一会,模拟器的速度终于可以快过真机啦
- 【C++自我精讲】基础系列二 const
- Windows多进程编程 .
- jsopu getElementsByClass 遇到空格无法解析的解决办法
- hdu 1348 Wall(凸包模板)
- 微软笔试
- Oracle学习(13)---Logminer
- service-based database
- vmware设置centos虚拟机nat联网
- Linux系统服务器错误信息的解释
- Linux 更改主机的 host 名
- CSDN博客
- 服务器参数知多少 带你一一认识这些参数