题目描述:

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. HTTP之间的区别和特性

    一. Http 简介 Http,学名超文本传输协议 它理解起来并不复杂,平时并不起眼,但经常使用; 前后端交互,多数依赖于http协议,重要性看个人理解,我不敢使用个人认为不掌握的技术; 二. HTT ...

  2. jQuery EasyUI/TopJUI创建日期时间输入框

    jQuery EasyUI/TopJUI创建日期时间输入框 日期时间输入框组件 HTML 和日期输入框类似,日期时间输入框允许用户选择日期和指定的时间并按照指定的输出格式显示.相比日期输入框,它在下拉 ...

  3. 【VueJS】VueJS开发请求本地json数据的配置

    VueJS开发请求本地json数据的配置,旧版本是build/dev-server.js,新版本是build/webpack.dev.conf.js. VueJS开发请求本地json数据的配置,早期的 ...

  4. ·ios 圆角

    uiview 直接设置 view.layer.cornerRadius = 5 uiimageview 还需要在设置view.layer.masksToBounds = true .uiview设置这 ...

  5. Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D

    Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and g ...

  6. Ocelot API

    Ocelot API网关的实现剖析   在微软Tech Summit 2017 大会上和大家分享了一门课程<.NET Core 在腾讯财付通的企业级应用开发实践>,其中重点是基于ASP.N ...

  7. 课程增加功能(java web)

    1.设计思想 先写类DBUtil用来连接数据库.在UserDaoImpl2类中写在数据库中添加课程表信息的方法.然后定义类Calss2来写保存超级课表数据:课程名称,任课教师,上课地点的属性及其get ...

  8. Linux 解压压缩war包

    jar -xvf aaa.war   (jar只能解压war 包到当前目录下) unzip aaa.war -d aaa/   (解压war包到aaa目录下) 打包aaa 下的所有文件为aaa.war ...

  9. Storm编程入门API系列之Storm的Topology的stream grouping

    概念,见博客 Storm概念学习系列之stream grouping(流分组) Storm的stream grouping的Shuffle Grouping 它是随机分组,随机派发stream里面的t ...

  10. java 通用查询框架Querydsl 简介

    Querydsl 是一个通用的查询框架,专注于通过JavaAPI构建类型安全的SQL查询说说Querydsl的优势吧: 1. Querydsl支持代码自动完成,因为才纯Java API编写查询,因此主 ...