【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& ...
随机推荐
- poj1416 Shredding Company
Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5379 Accepted: 3023 ...
- WMSYS.WM_CONCAT(distinct(字段名)) 函数,字符串拼接函数。合并列
合并列函数 WMSYS.WM_CONCAT(distinct(字段名)) 函数 可以实现字符串拼接在一起,这种情况可以在要求把一个字段的多个值拼接在一起的时候使用.其中distinct可以去掉重复的值 ...
- Java synchronized
1. 将synchronized加在方法上, 即可实现对此方法的同步 public synchronized void deposit(float amt) { float tmp = amount; ...
- 数据类型之记录(record)..With XXX do begin... end;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 type Mai ...
- SQL SERVER 系统库查询
本文内容主要来自网络,如有错误请路过的大牛指点迷津. 1.sqlserver 数据库最大并发连接数 sqlserver的最大连接数虽然说是不限制,但实际的限制数量是32767,如果需要超出这个数量,一 ...
- jboss CLI 命令行接口学习(适用JBOSS EAP 6.2+)
一.确认CLI所使用的端口 以domain模式为例,查看domain controller(也就是master主机)上的host.xml <management-interfaces> & ...
- 纯手工打造漂亮的瀑布流,五大插件一个都不少Bootstrap+jQuery+Masonry+imagesLoaded+Lightbox!
前两天写的文章<纯手工打造漂亮的垂直时间轴,使用最简单的HTML+CSS+JQUERY完成100个版本更新记录的华丽转身!>受到很多网友的喜爱,今天特别推出姊妹篇<纯手工打造漂亮的瀑 ...
- Webwork 学习之路【03】核心类 ServletDispatcher 的初始化
1. Webwork 与 Xwork 搭建环境需要的的jar 为:webwork-core-1.0.jar,xwork-1.0.jar,搭建webwork 需要xwork 的jar呢?原因是这样的,W ...
- JavaScript Array
1.常用方法 // 数组构造 var a = new Array(20); // 长度为20的数组 var b = new Array('red', 'blue', 'white'); var c = ...
- 基于DDD的.NET开发框架 - ABP启动配置
返回ABP系列 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB应 ...