POJ 1113 Wall(凸包)
来源:互联网 发布:php input 获取date 编辑:程序博客网 时间:2024/06/05 22:52
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
结果四舍五入就可以了
题目大意:
给定一些点,这些点围城了一个多边形,要求用墙将这个多边形围住且墙与多边形每处的距离均不小于L,求墙的最小长度。
解题思路:
算是凸包裸题吧,需要注意的是要保持L的距离,其实根据题目上的图可以看出来,除了圆角部分,其余部分都与多边形对应部分平行且相等,这样总的长度就等于这个多边形凸包的长度加上那些圆角部分的长度,圆角部分是一系列的圆弧,因为整个墙是围起来的,所以所有圆弧对应的圆心角之和为360度,半径为L,所以整个墙的长度就等于多边形凸包的长度加上半径为L的圆的周长。
#include <iostream>#include <fstream>#include <cstdio>#include <cmath>#include <map>#include <set>#include <bitset>#include <ctime>#include <cstring>#include <algorithm>#include <stack>#include <queue>#include <vector>#include <list>#define STD_REOPEN() freopen("../in.in","r",stdin)#define STREAM_REOPEN fstream cin("../in.in")#define INF 0x3f3f3f3f#define _INF 63#define eps 1e-8#define MAX_V 100010#define MAX_P 110#define MAX_E 10010#define MAX 32000#define MOD_P 3221225473#define MOD 9901using namespace std;struct Point{double x,y;Point(){}Point(double a,double b):x(a),y(b){}Point operator - (const Point a)const//求向量{return Point(x-a.x,y-a.y);}double operator ^ (const Point a)const//叉乘{return (x*a.y)-(y*a.x);}double operator & (const Point a)const//两点间距离{return sqrt((x-a.x)*(x-a.x)+(y-a.y)*(y-a.y));}bool operator < (const Point a)const{if(y==a.y)return x<a.x;return y<a.y;}}s[1010];double GrahamScan(int n){sort(s,s+n);Point res[1010];int top=0;for(int i=0;i<n;i++){while(top>=2&&(Point(res[top-1]-res[top-2])^Point(s[i]-res[top-2]))<0)top--;res[top++]=s[i];}int len=top+1;for(int i=n-2;i>=0;i--){while(top>=len&&(Point(res[top-1]-res[top-2])^Point(s[i]-res[top-2]))<0)top--;res[top++]=s[i];}double ans=0;for(int i=0;i<top-1;i++)ans+=res[i]&res[i+1];return ans;}int main(){//STD_REOPEN();int n,l;while(~scanf("%d %d",&n,&l)){for(int i=0;i<n;i++)scanf("%lf %lf",&s[i].x,&s[i].y);double ans=GrahamScan(n);ans+=acos(-1.0)*2.0*l;//不要忘记最后加上圆的周长printf("%.0f\n",ans);} return 0;}
0 0
- POJ 1113 WALL (凸包问题)
- POJ 1113 Wall (凸包)
- poj 1113 Wall(凸包周长)
- POJ 1113 Wall (凸包)
- POJ 1113 Wall (凸包)
- poj 1113 wall (凸包)
- poj 1113wall (凸包)
- 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 (凸包)
- 对比MIUI7和Flyme4.5 期待神秘的Flyme5
- 近期计划
- 【unity编辑器拓展】unity spriteRender图层管理工具(支持Spine)
- linux常用命令(10):cat命令
- 求左下角星星之和 树状数组或线段树 poj 2352 Stars
- POJ 1113 Wall(凸包)
- Spectral Clustering(学习Free Mind知识整理)
- loadrunner监控Windows之前需要做的准备工作
- Mybatis
- Windows windows7 关闭隧道适配器
- 可牛影像动感渐隐闪图教程
- 有点击效果的xml资源文件
- android中canvas.drawText参数的介绍以及绘制一个文本居中的案例
- c#中两种不同的存储过程调用与比较