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

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=205;
const double eps=1e-6;
int n;
struct dian
{
double x,y;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a)
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a)
{
return dian(x-a.x,y-a.y);
}
dian operator * (const double &a) const
{
return dian(x*a,y*a);
}
dian operator / (const double &a) const
{
return dian(x/a,y/a);
}
}p[N];
struct bian
{
dian s,v;
bian(dian S=dian(),dian V=dian())
{
s=S,v=V;
}
}b[N],l[N],s[N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
double cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
double mj(dian a,dian b,dian c)
{
return cj(b-a,c-a)/2;
}
dian jd(bian x,bian y)
{
return x.s+x.v*(cj(x.s-y.s,y.v)/cj(y.v,x.v));
}
bool px(bian a,bian b)
{
return cj(a.v,b.v)==0;
}
bool bn(bian a,bian b)
{
int ar=cj(a.v,b.v);
return ar>0||(ar==0&&cj(a.v,b.s-a.s)>0);
}
bool dn(dian x,bian y)
{
return cj(y.v,x-y.s)<=0;
}
bool cmp(const bian &x,const bian &y)
{
if(x.v.y==0&&y.v.y==0)
return x.v.x<y.v.x;
if((x.v.y<=0)==(y.v.y<=0))
return bn(x,y);
return x.v.y<y.v.y;
}
double dis2(bian a)
{
return sqrt(a.v.x*a.v.x+a.v.y*a.v.y);
}
bian yi(bian a,double r)
{
return bian(dian(a.s.x-a.v.y*r/dis2(a),a.s.y+a.v.x*r/dis2(a)),a.v);
}
bool ok(double r)
{
for(int i=1;i<=n;i++)
l[i]=yi(b[i],r);
sort(l+1,l+1+n,cmp);
int top=0;
for(int i=1;i<=n;i++)
if(i==1||!px(l[i],l[i-1]))
l[++top]=l[i];
n=top;
int ll=1,rr=2;
s[1]=l[1],s[2]=l[2];
for(int i=3;i<=n;i++)
{
while(ll<rr&&dn(jd(s[rr],s[rr-1]),l[i]))
rr--;
while(ll<rr&&dn(jd(s[ll],s[ll+1]),l[i]))
ll++;
s[++rr]=l[i];
}
while(ll<rr&&dn(jd(s[rr],s[rr-1]),s[ll]))
rr--;
return rr-ll>1;
}
int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=1;i<=n;i++)
p[i].x=read(),p[i].y=read();
p[n+1]=p[1];
for(int i=1;i<=n;i++)
b[i]=bian(p[i],p[i+1]-p[i]);
double l=0,r=10005,ans=0;
while(r-l>=eps)
{
double mid=(l+r)/2;//printf("%.6f\n",mid);
if(ok(mid))
l=mid,ans=mid;
else
r=mid;
}
printf("%.6f\n",ans);
}
return 0;
}

poj 3525Most Distant Point from the Sea【二分+半平面交】的更多相关文章

  1. poj3525Most Distant Point from the Sea(半平面交)

    链接 求凸多边形内一点距离边最远. 做法:二分+半平面交判定. 二分距离,每次让每条边向内推进d,用半平面交判定一下是否有核. 本想自己写一个向内推进..仔细一看发现自己的平面交模板上自带.. #in ...

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

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

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

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

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

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

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

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

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

  7. UVa 1475 (二分+半平面交) Jungle Outpost

    题意: 有n个瞭望塔构成一个凸n边形,敌人会炸毁一些瞭望台,剩下的瞭望台构成新的凸包.在凸多边形内部选择一个点作为总部,使得敌人需要炸毁的瞭望塔最多才能使总部暴露出来.输出敌人需要炸毁的数目. 分析: ...

  8. [HNOI2012][BZOJ2732] 射箭 [二分+半平面交]

    题面 BZOJ题面 思路 半平面交代码讲解戳这里,用的就是这道题 我们射箭的函数形如$y=Ax^2+Bx$ 考虑每一个靶子$(x_0,y_1,y_2)$,实际上是关于$A,B$的不等式限制条件 我们只 ...

  9. 二分+半平面交——poj1279

    /* 二分距离,凸包所有边往左平移这个距离,半平面交后看是否还有核存在 */ #include<iostream> #include<cstring> #include< ...

随机推荐

  1. Search in Rotated Sorted Array(二分查找)

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  2. Atom替换换行符

    直接[Ctrl]+[F],然后选择正则,输入\n

  3. Spring中使用Log4j记录日志

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/logging-with-log4j.html: 例子: pom.xml: <project ...

  4. influxDB系列(一)

    这个是github上面一个人总结的influxDB的操作手册,还不错:https://xtutu.gitbooks.io/influxdb-handbook/content/zeng.html 1. ...

  5. android多个fragment返回键层层返回

    在FragmentActivity的fragment跳转的时候加入到执行栈. public void switchFrag(BaseFragment to) { getSupportFragmentM ...

  6. jason数据格式 -- 扫盲

    JSON是 JavaScript Object Notation的简称,是一种轻量的数据表示方法.jason格式採用key:value的方式记录数据,非常直观,比XML简洁,因而大受欢迎 介绍jaso ...

  7. SQL 用于各种数据库的数据类型

    SQL 用于各种数据库的数据类型 Microsoft Access.MySQL 和 SQL Server 所使用的数据类型和范围. Microsoft Access 数据类型 数据类型 描述 存储 T ...

  8. Android四大组件与进程启动的关系(转)

    一. 概述 Android系统将进程做得很友好的封装,对于上层app开发者来说进程几乎是透明的. 了解Android的朋友,一定知道Android四大组件,但对于进程可能会相对较陌生. 一个进程里面可 ...

  9. Spring MVC @ResponseBody响应中文乱码

    问题:在前端通过get请求服务端返回String类型的服务时,会出现中文乱码问题 原因:由于spring默认对String类型的返回的编码采用的是 StringHttpMessageConverter ...

  10. OC基础:Date

    NSDate  日期类,继承自NSObject,代表一个时间点 NSDate *date=[NSDate date]; NSLog(@"%@",date);   //格林尼治时间, ...