poj1113——Wall(计算几何凸包)
2013-04-15 18:58
465 查看
Wall
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 25236Accepted: 8409
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.
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.
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 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200
Sample Output
1628
Hint
结果四舍五入就可以了
Source
Northeastern Europe 2001
解析:
题目就是求一个凸包的周长+圆周长的和。。。
至于证明也很简单。。。
证明如下:
假如顺时针给出四个点A、B、C、D。组成了凸四边形ABCD。我们不妨过A点作AE垂直于AB,同时过A点再作AF垂直于AD,过B点作BG、BH分别垂直于AB、BC。连结EG,垂线段的长度为L,过A点以AE为半径作一段弧连到AF,同理,使GH成为一段弧。此时EG=AB(边),AB段城墙的最小值为EF+弧EF+弧GH=AB+弧EF+弧GH。对所有点进行同样的操作后,可知城墙的最小值=四边形的周长+相应顶点的弧长(半径都为L)之和。
下面证明这些顶点弧长组成一个圆。依然以前面的四边形为例。A、B、C、D四顶点各成周角,总和为360*4=1440度,四边形内角和为360度,每个顶点作两条垂线,总角度为4*2*90=720度,所以总圆周角为1440-360-720=360度,刚好组成圆。
所以四边形ABCD的围墙最短= 四边形的周长+圆周长。
代码:
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 25236Accepted: 8409
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.
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.
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 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200
Sample Output
1628
Hint
结果四舍五入就可以了
Source
Northeastern Europe 2001
解析:
题目就是求一个凸包的周长+圆周长的和。。。
至于证明也很简单。。。
证明如下:
假如顺时针给出四个点A、B、C、D。组成了凸四边形ABCD。我们不妨过A点作AE垂直于AB,同时过A点再作AF垂直于AD,过B点作BG、BH分别垂直于AB、BC。连结EG,垂线段的长度为L,过A点以AE为半径作一段弧连到AF,同理,使GH成为一段弧。此时EG=AB(边),AB段城墙的最小值为EF+弧EF+弧GH=AB+弧EF+弧GH。对所有点进行同样的操作后,可知城墙的最小值=四边形的周长+相应顶点的弧长(半径都为L)之和。
下面证明这些顶点弧长组成一个圆。依然以前面的四边形为例。A、B、C、D四顶点各成周角,总和为360*4=1440度,四边形内角和为360度,每个顶点作两条垂线,总角度为4*2*90=720度,所以总圆周角为1440-360-720=360度,刚好组成圆。
所以四边形ABCD的围墙最短= 四边形的周长+圆周长。
代码:
#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> using namespace std; #define pi 3.141592654 int stack[1010],tu[1010]; int n,l; struct node{int x,y;}P[1010]; bool cmp(node a,node b) { if(a.x==b.x) return a.y<b.y; return a.x<b.x; } bool check(int p1,int p2,int p3) { int xx=P[p2].x-P[p1].x; int yy=P[p2].y-P[p1].y; int xxx=P[p3].x-P[p2].x; int yyy=P[p3].y-P[p2].y; return xx*yyy-xxx*yy>=0; } double dis(int i,int j) { return sqrt(double((P[i].x-P[j].x)*(P[i].x-P[j].x))+double((P[i].y-P[j].y)*(P[i].y-P[j].y))); } void read() { freopen("poj1113.in","r",stdin); freopen("poj1113.out","w",stdout); scanf("%d%d",&n,&l); for(int i=1;i<=n;i++) scanf("%d%d",&P[i].x,&P[i].y); } void work() { sort(P+1,P+n+1,cmp); int t; stack[1]=1;t=1; for(int i=2;i<=n;i++) { while(t>1 && !check(stack[t-1],stack[t],i))t--; //只要找得到凹包就出栈 stack[++t]=i; //每个点入一次栈 } int e=1; for(int i=1;i<=t;i++)tu[e++]=stack[i]; int sum=t; stack[1]=n;t=1; //求凸包的上面一块 for(int i=n-1;i>=1;i--) { while(t>1 && !check(stack[t-1],stack[t],i))t--; stack[++t]=i; } for(int i=1;i<=t;i++)tu[e++]=stack[i]; double ans=0; for(int i=2;i<e;i++) { ans+=dis(tu[i-1],tu[i]); } ans+=2*pi*l; printf("%.0lf\n",ans); } int main() { read(); work(); return 0; }
相关文章推荐
- POJ-1113 Wall 计算几何 求凸包
- POJ1113(Wall) && Hdu1392(Surround the Trees) (计算几何--凸包)
- POJ 1113 Wall (计算几何-凸包)
- POJ 1113 WALL(凸包-计算几何)
- POJ 1113 Wall (计算几何-凸包)
- POJ - 1113 Wall(计算几何凸包)
- POJ1113---Wall(基础计算几何:凸包入门)
- 【计算几何】【求凸包】【POJ 1113】wall
- poj 1113 Wall 计算几何 凸包 Graham扫描
- POJ 1113 Wall(计算几何--凸包的周长)
- 计算几何:极角排序(poj 2007 Scrambled Polygon)与简单凸包(poj 1113 Wall)
- poj 1113:Wall(计算几何,求凸包周长)
- poj 1113 计算几何 凸包
- poj 1113 Wall (计算几何)
- POJ训练计划1113_Wall(几何/凸包)
- poj 1113 凸包+简单几何计算
- POJ 1113(计算几何初步——凸包加圆周长)
- 计算几何初步之凸包(POJ 1113、2007、1873、1228、3348)
- [计算几何-凸包]pku1113-Wall
- 简单几何(凸包) POJ 1113 Wall