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 ...
随机推荐
- Maven的相关问题(一)——settings.xml配置详解
工作中第一次正式接触maven,虽然之前在学习时有遇到过,但是对于maven的认识和理解确实太浅薄,仅仅局限于机械式的操,纸上得来终觉浅,绝知此事要躬行···古人诚不欺我也~ 下面先贴一个找到的一个非 ...
- 航空售票系统设计分析(Markdownpad2图片服务器上传无法显示)
一.体系结构设计 1.系统原型图 2.体系结构环境图 3.构建结构图 二.人机交互界面设计 1.用户分析结果及建议 本次分析的主要目标关注用户评论反馈,对反馈进行归纳,设计出用户喜欢的界面样式.用户的 ...
- solr 简要笔记
创建搜索1 创建directory 2.分词器 analyzer 3indexwriter writer dic an 4.document doc.add writer.adddocument(do ...
- 成长笔记 - mysql-5.5.25-winx64安装步骤(及密码修改问题)
操作系统:Windows 7 64位 下载地址: http://download.mysql.cn/src/2012/0602/5611.html 1. 将mysql-5.5.25-winx64.zi ...
- scrapy的自动限速(AutoThrottle)扩展
该扩展能根据Scrapy服务器及您爬取的网站的负载自动限制爬取速度. 设计目标 更友好的对待网站,而不使用默认的下载延迟0. 自动调整scrapy来优化下载速度,使得用户不用调节下载延迟及并发请求数来 ...
- nuxt.js 加百度统计
Mark一下: 在 Nuxt.js应用中使用Google统计分析服务,或者百度统计分析服务,推荐在 plugins 目录下创建 plugins/ga.js 文件.统计统计分析我们可以获取网站pv,uv ...
- Mac电脑解压文件unrar用密码问题解决
下载了一个rar文件,有密码的,你懂的. 但是在mac上面,用unrar解压,只能解出空文件:用izip解压,直接停在那里不动. 只好上网搜索.找到了办法. 用brew 安装了命令行版本的 unrar ...
- Android安全机制介绍
Android的安全机制包含下面几个方面: • 进程沙箱隔离机制. • 应用程序签名机制. • 权限声明机制. • 訪问控制机制. • 进程通信机制. ...
- Drozer
Drozer原名mercury,是一款不错的Android APP安全评估工具.现在有社区版/专业版两个版本 本教程针对于Windows平台下drozer的安装与使用.使用该工具需要JDK的支持,所以 ...
- C开发人员眼中的SICP学习
谈谈自己看SICP的一些体会 第一章 构造过程抽象 这一章事实上和C语言全然等价, 不打算深入学习LISP的能够高速略过. 思想上没有太多新的东西. 这一章最核心的价值就是以下3句话, 理解了这一章 ...