POJ1113 Wall —— 凸包
题目链接:https://vjudge.net/problem/POJ-1113
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 39281 | Accepted: 13418 |
Description

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
Source
题意:
给出一座城堡(由点勾勒出来),问用最短城墙将城堡包围起来,且城墙与城堡的距离不能小于L。
题解:
1.假设没有规定城堡与城墙的距离,那么城墙的最短长度即为城墙点集的凸包的周长。
2.再考虑回城墙与城堡的距离,那么就要把凸包的每条边往外垂直移动L距离。移动过后,每条边与相邻的边都没有了交点,这时,需要在两条边之间加一段圆弧,圆弧的半径即为L,而所有圆弧加起来就是一个完整的圆,为什么?如图:

再根据初中知识:任意多边形的外角和为360度。即可得出结论。
4.所以总长度为:凸包的周长+圆的周长。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = +; const double eps = 1e-;
const double PI = acos(-1.0);
int sgn(double x)
{
if(fabs(x)<eps) return ;
if(x<) return -;
else return ;
} struct Point
{
double x,y;
Point(){}
Point(double _x, double _y) {
x = _x; y = _y;
}
Point operator -(const Point &b)const{
return Point(x-b.x, y-b.y);
}
double operator *(const Point &b)const{
return x*b.x+y*b.y;
}
double operator ^(const Point &b)const{
return x*b.y-y*b.x;
}
}; Point list[MAXN];
int Stack[MAXN], top; double dis(Point a, Point b)
{
return sqrt((a-b)*(a-b));
} bool cmp(Point p1, Point p2)
{
double tmp = (p1-list[])^(p2-list[]);
if(sgn(tmp)>) return true;
else if(sgn(tmp)== && sgn(dis(p1,list[])-dis(p2,list[]))<=)
return true;
else return false;
} void Graham(int n)
{
Point p0;
int k = ;
p0 = list[];
for(int i = ; i<n; i++)
{
if(p0.y>list[i].y||(p0.y==list[i].y&&p0.x>list[i].x))
{
p0 = list[i];
k = i;
}
}
swap(list[k],list[]);
sort(list+,list+n,cmp);
if(n==)
{
top = ;
Stack[] = ;
return;
}
if(n==)
{
top = ;
Stack[] = ;
Stack[] = ;
return;
}
Stack[] = ;
Stack[] = ;
top = ;
for(int i = ; i<n; i++)
{
while(top> && sgn((list[Stack[top-]]-list[Stack[top-]])^(list[i]-list[Stack[top-]]))<=)
top--;
Stack[top++] = i;
}
} int main()
{
int L, n;
while(scanf("%d%d", &n,&L)!=EOF)
{
for(int i = ; i<n; i++)
scanf("%lf%lf",&list[i].x,&list[i].y); Graham(n);
double perimeter = ;
for(int i = ; i<top; i++)
perimeter += dis(list[Stack[i]],list[Stack[(i+)%top]]);
perimeter += 2.0*PI*L;
printf("%.0f\n", perimeter);
}
}
POJ1113 Wall —— 凸包的更多相关文章
- POJ1113:Wall (凸包算法学习)
题意: 给你一个由n个点构成的多边形城堡(看成二维),按顺序给你n个点,相邻两个点相连. 让你围着这个多边形城堡建一个围墙,城堡任意一点到围墙的距离要求大于等于L,让你求这个围墙的最小周长(看成二维平 ...
- POJ1113:Wall (凸包:求最小的多边形,到所有点的距离大于大于L)
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the ...
- POJ1113 Wall 凸包
题目大意:建立围墙将城堡围起来,要求围墙至少距离城堡L,拐角处用圆弧取代,求围墙的长度. 题目思路:围墙长度=凸包周长+(2*PI*L),另外不知道为什么C++poj会RE,G++就没问题. #inc ...
- POJ1113 Wall
题目来源:http://poj.org/problem?id=1113题目大意: 如图所示,给定N个顶点构成的一个多边形和一个距离值L.建立一个围墙,把这个多边形完全包含在内,且围墙距离多边形任一点的 ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- POJ-1113 Wall 计算几何 求凸包
题目链接:https://cn.vjudge.net/problem/POJ-1113 题意 给一些点,求一个能够包围所有点且每个点到边界的距离不下于L的周长最小图形的周长 思路 求得凸包的周长,再加 ...
- POJ1113 Wall【凸包】
题意: 求把城堡围起来需要的最小墙壁周长. 思路: 围墙周长为=n条平行于凸包的线段+n条圆弧的长度=凸包周长+围墙离城堡距离L为半径的圆周长. 代码: ...还是看大佬写的,自己做个记录方便日后复习 ...
- POJ 1113 - Wall 凸包
此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...
- hdu 1348 Wall (凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
随机推荐
- HDFS冗余数据块的自动删除
HDFS冗余数据块的自动删除 在日常维护hadoop集群的过程中发现这样一种情况: 某个节点由于网络故障或者DataNode进程死亡,被NameNode判定为死亡,HDFS马上自动开始数据块的容错拷贝 ...
- 2016.11.10 Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver
运行项目rds_web时,出现错误提示:Could not get JDBC Connection; nested exception is java.sql.SQLException: No sui ...
- Php网站如何优化才好?
尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍. 当然了,这个测试方法需要在十万级以上次执行,效果才明显. 其实静态方法和非 ...
- 将ActiveX控件标记为安全
參考网页 http://msdn.microsoft.com/en-us/library/aa751977(v=vs.85).aspx http://support.microsoft.com/kb/ ...
- Problem F
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submission(s) ...
- 【Python】python3中urllib爬虫开发
以下是三种方法 ①First Method 最简单的方法 ②添加data,http header 使用Request对象 ③CookieJar import urllib.request from h ...
- .net 添加web引用和添加服务引用有什么区别?
添加web引用和添加服务引用有什么区别, Add Service References 和 Add Web References 有啥区别? 参考 http://social.microsoft.co ...
- 【Sprint3冲刺之前】TD学生助手——alpha版发布
TD学生助手——alpha版发布 1.设想和目标 1.我们的软件要解决的问题 TD学生助手的主要核心思想就是帮助学生安排他们忙碌的学校生活.主要是通过以下几个方面 1.通过学生的需要进行分类(考试, ...
- XTUOJ 1176 I Love Military Chess(模拟)
I Love Military Chess Accepted : 45 Submit : 141 Time Limit : 1000 MS Memory Limit : 65536 KB ...
- 【C语言天天练(二)】statickeyword
引言: statickeyword不仅能够修饰变量.并且能够修饰函数.了解它的使用方法,不仅对阅读别人的代码有帮助,也有助于自己写出更加健壮的程序. 使用方法: ...