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 ...
随机推荐
- VUE 路由变化页面数据不刷新问题
出现这种情况是因为依赖路由的params参数获取写在created生命周期里面,因为相同路由二次甚至多次加载的关系 没有达到监听,退出页面再进入另一个文章页面并不会运行created组件生命周期,导致 ...
- 【Python】随机漫步
创建Randomwalk()类 我们将使用Python来生成随机漫步数据,再使用matplotlib以引入瞩目的方式将这些数据呈现出来 首先创建类Randomwalk() from random im ...
- c# 推荐5款超实用的.NET性能分析工具
虽然.NET框架号称永远不会发生内存泄漏,原因是引入了内存回收机制.但在实际应用中,往往我们分配了对象但没有释放指向该对象的引用,导致对象永远无法释放.最常见的情况就是给对象添加了事件处理函数,但当不 ...
- C语言之基本算法32—鞍点
//数组 /* ================================================================== 题目:求随意矩阵的全部鞍点.并统计个数.(在矩阵中 ...
- 抽象类(abstract)和接口(interface)的区别
1 抽象类是不能被实例化的类,只能作为由其他类继承的基类: 接口则定义了实现某种服务的一般规范(Objective-C中将接口称为“协议”(protocol)),声明了必需的函数和常量,但不指定 ...
- CSS3 background属性
background: #00FF00 url(bgimage.gif) no-repeat fixed top; background 简写属性在一个声明中设置所有的背景属性. 可以设置如下属性: ...
- android 怎样单独下载一个项目
起因,"网络"不太好."比方铁通的就是不如联通的" 每次运行一边repo sync,十分蛋疼,假设不做full build无需所有下载,着急看某个项目的修改但是 ...
- windows下rsync部署安装
windows下rsync部署安装 2012-06-05 12:06:13| 分类: 系统 | 标签:rsync windows |字号 订阅 rsync在windows与windows ...
- 开发ActiveX控件调用另一个ActiveX系列0——身份证识别仪驱动的问题
程序员要从0下表开始,这篇是介绍这个系列的背景的,没有兴趣的人可以直接跳过. 为什么要开发ActiveX控件 由于工作需要,我们开发了一个网站,使用了一款身份证识别仪的网页ActiveX(OCX)插件 ...
- PHP和mysql的长连接
关于 PHP MySQL 长连接.连接池的一些探索 PHP连接MySQL的方式,用的多的是mysql扩展.mysqli扩展.pdo_mysql扩展,是官方提供的.php的运行机制是页面执行完会释放所有 ...