【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)
按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径。
二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了。
平移直线就是对于向量ab,因为是逆时针的,向中心平移就是向向量左手边平移,求出长度为r方向指向向量左手边的向量p,a+p指向b+p就是平移后的向量。
半平面交就是对于每个半平面ax+by+c>0,将当前数组里的点(一开始是所有点)带入,如果满足条件,那么保留该点,否则,先看i-1号点是否满足条件,如果满足,那么将i-1和i点所在直线和直线ax+by+c=0的交点加入数组,再看i+1号点如果满足条件,那么将i和i+1号点所在直线和直线ax+by+c=0的交点加入数组。最后看数组里有多少个点,如果0个点那么就是不存在半平面交。
要注意一下向量方向,半平面的直线的方向。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#define dd double
#define eps 1e-5
#define N 505
using namespace std;
int n;
struct Point{
dd x,y;
}p[N],tp[N],q[N];
dd osXoe(const Point &po,const Point &ps,const Point &pe){
return (ps.x-po.y)*(pe.y-po.y)-(pe.x-po.x)*(ps.y-po.y);
}
void eq(const Point &p1,const Point &p2,dd &a,dd &b,dd &c){
a=p2.y-p1.y;
b=p1.x-p2.x;
c=p2.x*p1.y-p1.x*p2.y;
}
Point cross(Point p1,Point p2,dd a,dd b,dd c){
dd u=fabs(a*p1.x+b*p1.y+c);
dd v=fabs(a*p2.x+b*p2.y+c);
Point t;
t.x=(p1.x*v+p2.x*u)/(u+v);
t.y=(p1.y*v+p2.y*u)/(u+v);
return t;
}
int Cut(dd a,dd b,dd c,int cnt){
int tmp=;
for (int i=;i<=cnt;i++){
if(a*p[i].x+b*p[i].y+c>-eps)tp[++tmp]=p[i];
else{
if(a*p[i-].x+b*p[i-].y+c>eps)
tp[++tmp]=cross(p[i-],p[i],a,b,c);
if(a*p[i+].x+b*p[i+].y+c>eps)
tp[++tmp]=cross(p[i],p[i+],a,b,c);
}
}
for (int i=;i<=tmp;i++)p[i]=tp[i];
p[]=p[tmp];p[tmp+]=p[];
return tmp;
}
int solve(dd r){
q[]=q[n];q[n+]=q[];
for (int i=;i<=n+;i++) p[i]=q[i];
int cnt=n;
for (int i=;i<=n;i++){
dd a,b,c;
Point p1,p2,p3;
p1.y=q[i+].x-q[i].x;p1.x=q[i].y-q[i+].y;
dd k=r/sqrt(p1.x*p1.x+p1.y*p1.y);
p1.x=k*p1.x;p1.y=k*p1.y;
//p1是垂直q[i+1]->q[i]指向右手边的长度为r的向量。如果是q[i]->q[i+1]则求指向左手边的。
p2.x=p1.x+q[i].x;p2.y=p1.y+q[i].y;
p3.x=p1.x+q[i+].x;p3.y=p1.y+q[i+].y;
eq(p3,p2,a,b,c);//过p3->p2的直线方程ax+by+c=0
cnt=Cut(a,b,c,cnt);//求半平面交剩下的点
}
return cnt;
}
int main(){
while(cin>>n,n){
for (int i=;i<=n;i++)
scanf("%lf%lf",&q[i].x,&q[i].y);
dd l=,r=<<,m;
while(fabs(r-l)>eps){
m=(l+r)/2.0;
if(solve(m))l=m;
else r=m;
}
printf("%.6f\n",m);
}
}
【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)的更多相关文章
- POJ 3525/UVA 1396 Most Distant Point from the Sea(二分+半平面交)
Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...
- POJ 3525 Most Distant Point from the Sea
http://poj.org/problem?id=3525 给出一个凸包,要求凸包内距离所有边的长度的最小值最大的是哪个 思路:二分答案,然后把凸包上的边移动这个距离,做半平面交看是否有解. #in ...
- POJ 3525 Most Distant Point from the Sea [半平面交 二分]
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5153 ...
- POJ 3525 Most Distant Point from the Sea (半平面交+二分)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3476 ...
- POJ 3525 Most Distant Point from the Sea (半平面交)
Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...
- POJ3525-Most Distant Point from the Sea(二分+半平面交)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3955 ...
- POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)
题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...
- POJ 3525 Most Distant Point from the Sea 二分+半平面交
题目就是求多变形内部一点. 使得到任意边距离中的最小值最大. 那么我们想一下,可以发现其实求是看一个圆是否能放进这个多边形中. 那么我们就二分这个半径r,然后将多边形的每条边都往内退r距离. 求半平面 ...
- poj 3525Most Distant Point from the Sea【二分+半平面交】
相当于多边形内最大圆,二分半径r,然后把每条边内收r,求是否有半平面交(即是否合法) #include<iostream> #include<cstdio> #include& ...
随机推荐
- Eclipse启动时选择workspace设置
由于一直习惯eclipse中只使用一个工作空间,所以一般在eclipse刚刚安装好后第一次启动时,我就钩上了弹出的工作空间选择的对话框中以后不再提示的钩选. 结果这次突然需要用到它的工作空间提示功能了 ...
- 转:Configure your eclipse for C++
from: http://omtlab.com/configure-your-eclipse-for-c/ Configure your eclipse for C++ July 7, 2013 Th ...
- 应用多个icon的对比
在给应用设计图标的时候,可能会遇到这样的需求,应用图标有老版和新版两种,而又想在桌面上同时显示这两个图标以对比效果. 一个应用本身只有一个自己的icon,在AndroidManifest.xml文件中 ...
- fancybox的配置项
Fancybox的API和配置选项说明 属性名 默认值 简要说明 padding 10 浏览框内边距,和css中的padding一个意思 margin 20 浏览框外边距,和css中的margin一个 ...
- xhprof使用笔记(非原创)
[作用] xhprof是facebook开源的一个php性能分析工具. [安装] xhprof扩展的安装: wget http://pecl.php.net/get/xhprof-0.9.2.tg ...
- codevs 3369 膜拜
3369 膜拜 http://codevs.cn/problem/3369/ 题目描述 Description 神牛有很多-当然-每个同学都有自己衷心膜拜的神牛.某学校有两位神牛,神牛甲和神牛乙.新入 ...
- redis 学习笔记(2)-client端示例代码
redis提供了几乎所有主流语言的client,java中主要使用二种:Jedis与Redisson 一.Jedis的使用 <dependency> <groupId>redi ...
- xmind 使用备忘
快捷键: shift+enter 编辑文字时回车换行 enter 快速建立同级主题(纵向) tab 快速建立子主题(横向) F4 插入注释 alt+左键+移动 拖动 shift+左键+移动 将元素脱离 ...
- 我们来八一八阿里云OS的实质和历史
有个姓许的朋友在微信公众号上这样评论: 但是楼主对yunos的了解程度有多少,建议去了解下再评价别人,免费给你普及下:http://www.ithome.com/html/digi/109484.ht ...
- Python面试题 —— 计算列表中出现最多次的字符
给你一个其中包含不同的英文字母和标点符号的文本,你要找到其中出现最多的字母,返回的字母必须是小写形式, 当检查最想要的字母时,不区分大小写,所以在你的搜索中 "A" == &quo ...