POJ1113:Wall (凸包:求最小的多边形,到所有点的距离大于大于L)
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
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
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
题意:给定N个点,求用一个多边形把这些点包括进去,且每个点到多边形的距离都大于等于L。
思路:
先不考虑L这个条件,因为两点之间,直线最短,所以对于凹进去的部分,我们肯定有最短的直线可以包含它,可以忽略,所以是求凸包。
然后考虑L,对于求出的凸多边形,对于它的顶点X,可以证明每个X附近需要增加一定的圆弧来保证顶点到圆弧的距离大于等于L,
所有X的圆弧角度之和为Pi,将凸包平移与圆弧连接成封闭图案,最终 ans=凸包+2*Pi*L。
看图就知道了--->
Graham算法求凸包:
(注意需要对N讨论,此题N>=3,所以没有讨论)。
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
const double pi=acos(-1.0);
const double eps=1e-;
struct Cpoint
{
double x,y;
Cpoint(){}
Cpoint(double xx,double yy):x(xx),y(yy){}
Cpoint friend operator -(Cpoint a,Cpoint b){
return Cpoint(a.x-b.x, a.y-b.y);
}
double friend operator ^(Cpoint a,Cpoint b){
return a.x*b.y-b.x*a.y;
}
bool friend operator <(Cpoint a,Cpoint b){
if(a.y==b.y) return a.x<b.x;
return a.y<b.y;
}
};
double dist(Cpoint a,Cpoint b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int Sign(double x)
{
if(x>=-eps&&x<=eps) return ;
if(x>eps) return ; return -;
}
int N,L; Cpoint P[maxn];
bool cmp(Cpoint a,Cpoint b)
{
int s=Sign((a-P[])^(b-P[]));
if(s>||(s==&&dist(a,P[])<dist(b,P[]))) return true;
return false;
}
double Graham() //如果N<3还得讨论一下。
{
double res=;
sort(P+,P+N+); //得到“原点 ”
sort(P+,P+N+,cmp); //得到积角序
int q[maxn],top=;
q[]=; q[]=; q[]=;
for(int i=;i<=N;i++){
while(top>&&Sign((P[q[top]]-P[q[top-]])^(P[i]-P[q[top]]))<=) top--;
q[++top]=i;
}
for(int i=;i<top;i++) res+=dist(P[q[i]],P[q[i+]]);
res=res+dist(P[q[top]],P[])+2.0*pi*L;
return res;
}
int main()
{
while(~scanf("%d%d",&N,&L)){
for(int i=;i<=N;i++)
scanf("%lf%lf",&P[i].x,&P[i].y);
printf("%d\n",(int)(Graham()+0.5));
}return ;
}
POJ1113:Wall (凸包:求最小的多边形,到所有点的距离大于大于L)的更多相关文章
- POJ1113:Wall (凸包算法学习)
题意: 给你一个由n个点构成的多边形城堡(看成二维),按顺序给你n个点,相邻两个点相连. 让你围着这个多边形城堡建一个围墙,城堡任意一点到围墙的距离要求大于等于L,让你求这个围墙的最小周长(看成二维平 ...
- POJ1113 Wall —— 凸包
题目链接:https://vjudge.net/problem/POJ-1113 Wall Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- POJ-1113 Wall 计算几何 求凸包
题目链接:https://cn.vjudge.net/problem/POJ-1113 题意 给一些点,求一个能够包围所有点且每个点到边界的距离不下于L的周长最小图形的周长 思路 求得凸包的周长,再加 ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
- POJ1113 Wall 凸包
题目大意:建立围墙将城堡围起来,要求围墙至少距离城堡L,拐角处用圆弧取代,求围墙的长度. 题目思路:围墙长度=凸包周长+(2*PI*L),另外不知道为什么C++poj会RE,G++就没问题. #inc ...
- LightOj1203 - Guarding Bananas(凸包求多边形中的最小角)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1203 题意:给你一个点集,求凸包中最小的角:模板题,但是刚开始的时候模板带错了,错的我 ...
- POJ1113 Wall
题目来源:http://poj.org/problem?id=1113题目大意: 如图所示,给定N个顶点构成的一个多边形和一个距离值L.建立一个围墙,把这个多边形完全包含在内,且围墙距离多边形任一点的 ...
- hdu 1348 Wall (凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)
称号: Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
随机推荐
- android之总结(一)——原
1,TextView 中实现跑马灯,需求:文字左边留置一段空白,不需要紧靠在左边:设置android:padding android:padding和android:layout_margin这个地方 ...
- Java 并发编程中的 Executor 框架与线程池
Java 5 开始引入 Conccurent 软件包,提供完备的并发能力,对线程池有了更好的支持.其中,Executor 框架是最值得称道的. Executor框架是指java 5中引入的一系列并发库 ...
- Oracle 实现 一个关键字 匹配多个 字段
有这么一个需求,满足只有一个输入框的条件下,支持不同数据列的搜索结果. 说白了,就是这个 输入框 既可以用来 搜索姓名,也可以搜索 年龄,地址等. 分析: 一般情况下,我们的一个输入框对应 数据库 ...
- python type()函数
我怎么把一个变量的类型写入文件?a = 3type(a)貌似返回的是type类型,不能打印,也不能用文件的write怎么半,或者怎么转换成srt之类的? type()函数得到的是一个类型而不是字符串, ...
- CODEVS_2800 送外卖 状态压缩+动态规划
原题链接:http://codevs.cn/problem/2800/ 题目描述 Description 有一个送外卖的,他手上有n份订单,他要把n份东西,分别送达n个不同的客户的手上.n个不同的客户 ...
- Spring实战Day6
3.4 bean的作用域 Spring中bean的作用域 单例(Singleton):在整个应用中,只创建bean的一个实例. 原型(Prototype):每次注入或者通过Spring应用上下文获取的 ...
- LSA、LDA
Latent semantic analysis (LSA) is a technique in natural language processing, in particular distrib ...
- 谷歌訪问之直接输入ip地址
废话啥说.直接上IP: 173.194.121.51 173.194.43.19 173.194.65.147 74.125.235.148
- Solidworks如何将参考平面的图形投影到某曲面上
1 画好草图,点击曲线-分割线 2 选择要投影的草图和被投影的面(那个球面),最后效果如下图所示 3 为了获取连续的轨迹,我们可以再次选择这个草图,然后在投影面中选择平面,最后得到的图形如下图 ...
- Solidworks修改零件文件名之后工程图找不到零件怎么办
如下图所示,如果我直接把"压紧柱 V1.0"改名为"压紧柱",则打开工程图之后图纸都没了. 即便你用打开零件的方式找到了这个零件,工程图还是老样子 所以 ...