相当于多边形内最大圆,二分半径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;
}

最新文章

  1. Scrum Meeting ——总结
  2. Android OpenCV 图像识别
  3. TYVJ P1069 cowtour 看不懂题意
  4. 【转】PackageInfo、ResolveInfo 笔记
  5. 单点登录 关于Cookie跨域的问题
  6. Linux 下五个顶级的开源命令行 Shell
  7. WCF入门(七)——异常处理1
  8. C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse
  9. Partition List ——LeetCode
  10. Lesson 2: Dive Into Typography (排版)
  11. MFC消息截获之pretranslatemessage
  12. 【智能家居篇】wifi网络接入原理(上)——扫描Scanning
  13. jquery中,使用append增加元素时,该元素的绑定监听事件失效
  14. 重新学习WCF
  15. 【建图+最短路】Bzoj1001 狼抓兔子
  16. TinScrapy-简化的Scrapy原码-查看爬虫的执行流程
  17. iOS开发基础篇-Button基础
  18. MMIO和PIO
  19. 为什么会出现Notice: Undefined index: submit in D:\xampp\htdocs\test.php on line 19
  20. MySQL注入与防御

热门文章

  1. Memcached Redis相关的干货
  2. OC-Xcode中导入runtime框架,函数参数没有提示的处理方法
  3. 编译.net .net Core程序 代码,仅做备份
  4. P2863 [USACO06JAN]牛的舞会The Cow Prom
  5. hdoj 3351 Seinfeld 【栈的简单应用】
  6. powerdesign导出SQL时自己主动生成凝视
  7. 在开发过程中,如何在手机上测试vue-cli构建的项目
  8. graph driver-device mapper-03thin pool基本操作
  9. 【iOS系列】-A server with the specified hostname could not be found.问题解决
  10. Linux的xshell命令