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 ...
随机推荐
- Shell脚本部分语法
Shell中的变量 Linux Shell中的变量分为“系统变量”和“用户自定义变量”,可以通过set命令查看那系统变量 系统变量:$HOME.$PWD.$SHELL.$USER等等 显示当前sh ...
- swfit各种Function表现形式
//: Playground - noun: a place where people can play import UIKit //多返回值函数 func countss(string: Stri ...
- 【AngularJS】Yeoman安装
看不到PPT的请自行解决DNS污染问题.
- .net mvc项目 ajax
经常在后台用一般处理程序(.ashx)来处理前台的ajax请求 using System; using System.Collections.Generic; using System.IO; usi ...
- 25:坐标移动CoordinateMove
题目描述 开发一个坐标计算工具, A表示向左移动,D表示向右移动,W表示向上移动,S表示向下移动.从(0,0)点开始移动,从输入字符串里面读取一些坐标,并将最终输入结果输出到输出文件里面. 输入: 合 ...
- *Android 多线程下载 仿下载助手
今天带来一个多线程下载的 样例.先看一下效果.点击 下载 開始下载,同一时候显示下载进度.完成下载,变成程 安装,点击安装 提示 安装应用. 界面效果 线程池 ThreadPoolExecutor , ...
- ubuntu16.04 Cmake学习二
本节主要总结编译程序的时候使用了第三方库的情况,以调用开源opencv-2.4.9为例子,具体安装详见http://www.cnblogs.com/xsfmg/p/5900420.html. 工程文件 ...
- VS中单元测试用法
using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTestProject1 { [Test ...
- OrCAD Capture出现丢失cdn_sfl401as.dll问题
昨天晚上我PCB图的时候还用OrCAD这个组件来着呢.但是还是好好的.但是今天当我再次启动程序的时候就出现了以下的对话框. 当时就吓了好一跳.好好软件怎么突然就不行了呢?先说说我出现这个问题之后的内心 ...
- android studio 更新Gradle版本号方法
在导入其它项目时,常常因为gradle版本号不一致而导致不能编译 解决方法: 第一步: 按提示点击让它下载.事实上目的并非要它下载.因为这样速度会非常慢.这样做仅仅是为了让它在本地创建相应的文件夹结构 ...