按逆时针顺序给出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(直线平移、半平面交)的更多相关文章

  1. 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 ...

  2. POJ 3525 Most Distant Point from the Sea

    http://poj.org/problem?id=3525 给出一个凸包,要求凸包内距离所有边的长度的最小值最大的是哪个 思路:二分答案,然后把凸包上的边移动这个距离,做半平面交看是否有解. #in ...

  3. POJ 3525 Most Distant Point from the Sea [半平面交 二分]

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5153   ...

  4. POJ 3525 Most Distant Point from the Sea (半平面交+二分)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3476   ...

  5. 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 ...

  6. POJ3525-Most Distant Point from the Sea(二分+半平面交)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3955   ...

  7. POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)

    题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...

  8. POJ 3525 Most Distant Point from the Sea 二分+半平面交

    题目就是求多变形内部一点. 使得到任意边距离中的最小值最大. 那么我们想一下,可以发现其实求是看一个圆是否能放进这个多边形中. 那么我们就二分这个半径r,然后将多边形的每条边都往内退r距离. 求半平面 ...

  9. poj 3525Most Distant Point from the Sea【二分+半平面交】

    相当于多边形内最大圆,二分半径r,然后把每条边内收r,求是否有半平面交(即是否合法) #include<iostream> #include<cstdio> #include& ...

随机推荐

  1. [No000033]码农网-如何锻炼出最牛程序员的编码套路

    最近,我大量阅读了Steve Yegge的文章.其中有一篇叫"Practicing Programming"(练习编程),写成于2005年,读后令我惊讶不已: 与你所相信的恰恰相反 ...

  2. SQL Server的各种聚合函数

    聚合函数是对一组值执行计算并返回单一的值的函数,它经常与SELECT语句的GROUP BY子句一同使用,SQL SERVER 中具体有哪些聚合函数呢?我们来一一看一下: 1. AVG 返回指定组中的平 ...

  3. Volley(二)—— 基本Request对象 & RequestQueue&请求取消

    详细解读Volley(一)—— 基本Request对象 & RequestQueue&请求取消 Volley它非常适合去进行数据量不大,但通信频繁的网络操作,而对于大数据量的网络操作, ...

  4. box-shadow 的一些使用

    1.只有左侧有阴影 box-shadow: -10px 0px 3px 1px #aaaaaa;

  5. Linux收集

    1.rsync快速删除文件 rsync --delete -avH /empty /rmdir 选项说明: –delete-before 接收者在传输之前进行删除操作 –progress 在传输时显示 ...

  6. win7的优化-1:隐藏我的电脑导航栏里的收藏等项目

    1. Type regedit in RUN or Start Menu search box and press Enter. It'll open Registry Editor. 2. Now ...

  7. CentOS搭建socket5代理服务器

    1.安装socket5依赖包 yum -y install gcc automake make pam-devel openldap-devel cyrus-sasl-devel   2.下载ss5并 ...

  8. ASP.NET MVC图片上传前预览

    回老家过春节,大半个月,在家的日子里,吃好睡好,人也长了3.5Kg.没有电脑,没有网络,无需写代码,工作上相关的完全放下......开心与父母妻儿过个年,那样的生活令Insus.NET现在还在留恋.. ...

  9. QT 对话框一

    标准文件对话框 其函数形式如下:: QString QFileDialog::getOpenFileName ( QWidget * parent=, const QString &capti ...

  10. PCL 库安装

    参考资料: http://www.cnblogs.com/newpanderking/articles/4022322.html VS2010+PCL配置 PCL共有两种安装方式 安全安装版,个人配置 ...