题目描述:

vjudge

POJ

题解:

二分答案+半平面交。

半径范围在0到5000之间二分,每次取$mid$然后平移所有直线,判断半平面交面积是否为零。

我的eps值取的是$10^{-12}$,36ms,而且和样例一样。

(大力推荐)

代码:

#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
const double eps = 1e-;
int dcmp(double x)
{
if(fabs(x)<=eps)return ;
return x>?:-;
}
struct Point
{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
Point operator + (const Point&a)const{return Point(x+a.x,y+a.y);}
Point operator - (const Point&a)const{return Point(x-a.x,y-a.y);}
Point operator * (const double&a)const{return Point(x*a,y*a);}
Point operator / (const double&a)const{return Point(x/a,y/a);}
double operator * (const Point&a)const{return x*a.x+y*a.y;}
double operator ^ (const Point&a)const{return x*a.y-y*a.x;}
};
typedef Point Vector;
typedef vector<Point> Pol;
double ang(const Vector&a){return atan2(a.x,a.y);}
double lth(const Vector&a){return sqrt(a*a);}
Vector Vil(const Vector&a){return Vector(-a.y,a.x)/lth(a);}
struct Line
{
Point p;
Vector v;
Line(){}
Line(Point p,Vector v):p(p),v(v){}
Line operator + (const Vector&a)const{return Line(p+a,v);}
bool operator < (const Line&a)const{return ang(v)<ang(a.v);}
};
int n;
Point p[N],tp[N];
Vector vp[N];
Line s0[N],s[N],ts[N];
bool Onleft(Line l,Point p)
{
return dcmp(l.v^(p-l.p))>;
}
Point L_L(Line a,Line b)
{
double t = ((b.p-a.p)^(b.v))/(a.v^b.v);
return a.p+a.v*t;
}
double S_(Pol&P)
{
double ans = 0.0;
for(int i=,lim=(int)P.size();i<lim;i++)
ans+=((P[i-]-P[])^(P[i]-P[]));
return fabs(ans)/;
}
double bpmj()
{
int hd,tl;
ts[hd=tl=]=s[];
for(int i=;i<=n;i++)
{
while(hd<tl&&!Onleft(s[i],tp[tl-]))tl--;
while(hd<tl&&!Onleft(s[i],tp[hd]))hd++;
ts[++tl] = s[i];
if(!dcmp(s[i].v^ts[tl-].v))
{
tl--;
if(Onleft(ts[tl],s[i].p))ts[tl]=s[i];
}
tp[tl-]=L_L(ts[tl-],ts[tl]);
}
while(hd<tl&&!Onleft(ts[hd],tp[tl-]))tl--;
if(tl-hd<=)return ;
tp[tl]=L_L(ts[hd],ts[tl]);
Pol P;
for(int i=hd;i<=tl;i++)P.push_back(tp[i]);
return S_(P);
}
bool check(double mid)
{
for(int i=;i<=n;i++)s[i]=s0[i]+vp[i]*mid;
return dcmp(bpmj())>;
}
int main()
{
while(scanf("%d",&n)&&n!=)
{
for(int i=;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
for(int i=;i<n;i++)s0[i]=Line(p[i],p[i+]-p[i]);
s0[n]=Line(p[n],p[]-p[n]);
sort(s0+,s0++n);
for(int i=;i<=n;i++)
vp[i]=Vil(s0[i].v);
double l = 0.0,r = 5000.0;
while(dcmp(r-l))
{
double mid = (l+r)/;
if(check(mid))l=mid;
else r=mid;
}
printf("%lf\n",r);
}
return ;
}

poj3525 Most Distant Point from the Sea的更多相关文章

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

    给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...

  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 [半平面交 二分]

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

  4. LA 3890 Most Distant Point from the Sea(半平面交)

    Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...

  5. 【POJ】【3525】Most Distant Point from the Sea

    二分+计算几何/半平面交 半平面交的学习戳这里:http://blog.csdn.net/accry/article/details/6070621 然而这题是要二分长度r……用每条直线的距离为r的平 ...

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

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

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

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

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

    pro:给定凸多边形,求凸多边形内的点到最近边界的最远距离. sol:显然是二分一个圆,使得圆和凸多边形不相交,但是这样很难实现. 由于是凸多边形,我们可以把二分圆转化为二分凸多边形的移动. 如果每一 ...

随机推荐

  1. argparse 在深度学习中的应用

    argparse 介绍 argparse模块主要用来为脚本传递命令参数功能,使他们更加灵活. 代码: parser = argparse.ArgumentParser() #建立解析器,必须写 par ...

  2. Java8 中的 Optional

    从 Java 8 引入的一个很有趣的特性是 Optional  类.Optional 类主要解决的问题是臭名昭著的空指针异常(NullPointerException) —— 每个 Java 程序员都 ...

  3. Unable to load EJB module

    http://stackoverflow.com/questions/12414526/unable-to-load-ejb-module

  4. feign客户端传参数报错

    新手经常遇到的错误 Caused by: java.lang.IllegalStateException: Method has too many Body parameters feign多参数问题 ...

  5. list 转换成datatable

    感谢网上的一位朋友 /// <summary> /// 将集合类转换成DataTable /// </summary> /// <param name="lis ...

  6. Java基础语法(Eclipse)

    Java基础语法 今日内容介绍 u Eclipse开发工具 u 超市库存管理系统 第1章 Eclipse开发工具 Eclipse是功能强大Java集成开发工具.它可以极大地提升我们的开发效率.可以自动 ...

  7. java的三大特性之一多态概述

    多态---概念 所谓多态就是一个引用在不同情况下的多种状态.多态是指通过指向父亲的指针,来调用在不同的子类中实现的方法. 多态---注意事项 00.java允许父类的引用变量引用它的子类的实例(对象) ...

  8. dubbo服务降级(1)

    1. 在 dubbo 管理控制台配置服务降级 上图的配置含义是:consumer 调用 com.zhang.HelloService 的方法时,直接返回 null,不发起远程调用. 实际操作是:在 z ...

  9. gitinore修改不生效

    .gitignore只能忽略那些尚未被被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的.一个简单的解决方法就是先把本地缓存删除(改变成未track状态),然后 ...

  10. CAS 配置NLB 负载均衡网络无法连接

    在虚拟机与虚拟机.虚拟机与实机之间利用Windows操作系统自带的网络负载均衡功能如选择单播集群模式,网络就无法通讯,NLB不成功. Scenario #1 在虚拟机与虚拟机之间选择多播模式NLB可正 ...