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 ...
随机推荐
- Redis性能调优建议
一. Redis部署结构优化建议 1. Master不做AOF或RDB持久化,Slave做AOF持久化,建议同时做RDB持久化 2. 所有Master全部增加Slave 3. Master挂载Slav ...
- 用循环将三个DIV变成红色
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- centos 安装 htop
centos-install-htop http://elearning.wsldp.com/pcmagazine/centos-install-htop/
- vue 监听 watch 使用
1.api https://cn.vuejs.org/v2/api/#watch 有2个配置: (1)深度 watcher deep: true(2)该回调将会在侦听开始之后被立即调用 immedia ...
- iphone手机分辨率--持久维护
6.5英寸 —— 1242 x 2688 px —— Xs Max 6.1英寸 —— 828 x 1792 px —— XR 5.8英寸 —— 1125 x 2436 px —— X/Xs 5.5英寸 ...
- LVS + KEEPALIVED + WINDOWS SERVER 2008 R2 ------高可用负载均衡(转)
工作原理此处不作讲解,自己去官方网站学习(http://www.linuxvirtualserver.org),这里重点讲如何配置!注:最好从官方网站对其进行了解,不至于会对某些问题产生误解,尽管是英 ...
- zabbix-agent active 配置自动探测
1. zabbix-agent 被动模式配置文件: PidFile=/var/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_a ...
- bugzilla 系列1安装
安装好mysql yum install gcc perl* mod_perl-devel -y wget https://ftp.mozilla.org/pub/mozilla.org/webtoo ...
- 【Android】图片(文件)上传的请求分析结构
怎么在android中上传文件,即怎么用Java向服务器上传文件.上传图片,这是个老问题了,在网上能搜到现成的代码,很多朋友用起来也比较熟了,但是为什么这么写,可能很多朋友并不清楚,这篇文章就来分析一 ...
- System.DateTime.Now.ToString()的一些用法
日期处理函数 //2007年4月24日 this.TextBox6.Text = System.DateTime.Now.ToString("D"); //200 ...