【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& ...
随机推荐
- Android中关于Volley的使用(五)从RequestQueue开始来深入认识Volley
在前面的几篇文章中,我们学习了如何用Volley去网络加载JSON数据,如何利用ImageRequest和NetworkImageView去网络加载数据,而关于Volley的使用,我们都是从下面一行代 ...
- flask表单提交的两种方式
一.通用方式 通用方式就是使用ajax或者$.post来提交. 前端html <form method="post" action="/mockservice&qu ...
- 树莓派B+安装archlinux arm版
按Archlinux官网操作而来,如有疑问参照官网:http://archlinuxarm.org/platforms/armv6/raspberry-pi 以我自己安装过程举例,我的SD卡挂载在ub ...
- python环境下载地址
python: https://www.python.org/downloads/ mysqlyog: http://down.liangchan.net/Webyog%20SQLyog%20Ulti ...
- nginx学习(1):编译、安装、启动
一.下载 从官网http://nginx.org/en/download.html 下载稳定版(目前最新稳定版是1.6.2) 二.解压 tar zxf nginx-1.6.2.tar.gzcd ngi ...
- vbs mytest
public Function SaveText(filePath,content)set fso=createobject("scripting.filesystemobject" ...
- FineUI v3.3.2发布!目前最稳定版本,五年陈酿!
关于FineUI基于 ExtJS 的专业 ASP.NET 控件库. FineUI的使命创建 No JavaScript,No CSS,No UpdatePanel,No ViewState,No We ...
- JavaScript Array
1.常用方法 // 数组构造 var a = new Array(20); // 长度为20的数组 var b = new Array('red', 'blue', 'white'); var c = ...
- 判断Laravel Eloquent获取数据结果集是否为空
在使用Laravel Eloquent模型时,我们可能要判断取出的结果集是否为空,但我们发现直接使用is_null或empty是无法判段它结果集是否为空的. var_dump之后我们很容易发现,即使取 ...
- ASP.NET的编译原理
http://www.cnblogs.com/mdy2001212/archive/2008/01/31/1060345.html