题目描述:

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. 安装mongo可视化管理工具mongo admin

    https://github.com/mrvautin/adminMongo github地址 安装要求下载下来,然后安装即可 中间出现了问题: 说是开了代理,可以关掉代理之后,然后把下载下来的删了, ...

  2. Kaggle 数据挖掘比赛经验分享

    文章发布于公号[数智物语] (ID:decision_engine),关注公号不错过每一篇干货. 来源 | 腾讯广告算法大赛 作者 | 陈成龙 Kaggle 于 2010 年创立,专注数据科学,机器学 ...

  3. 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower 解题报告

    一起来看流星雨吧(话说我还没看到过流星雨呢) 题目 Problem 小A则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽,届时将会对它撞到的一 ...

  4. 洛谷P3831 回家的路

    题目背景 SHOI2012 D2T1 题目描述 \(2046\) 年 \(OI\) 城的城市轨道交通建设终于全部竣工,由于前期规划周密,建成后的轨道交通网络由\(2n\)条地铁线路构成,组成了一个\( ...

  5. 洛谷P2971 牛的政治Cow Politics

    题目描述 Farmer John's cows are living on \(N (2 \leq N \leq 200,000)\)different pastures conveniently n ...

  6. dom4j解析简单的xml文件 解析元素并封装到对象

    package cn.itcast.xml; import cn.itcast.domain.Book; import org.dom4j.Document; import org.dom4j.Doc ...

  7. CF 700E

    构建后缀自动机,求出后缀树 比较明显的dp 设 \(f[i]\) 表示从上而下到达当前点能够满足条件的最优值 只需要检查父亲节点是否在当前串中出现过两次就行了 这个判断用 \(endpos\) 来判断 ...

  8. VS Code开发调试.NET Core 2.0

    VS Code开发调试.NET Core 2.0 使用VS Code 从零开始开发调试.NET Core 2.0.无需安装VS 2017 15.3+即可开发调试.NET Core 2.0应用. VS ...

  9. Ubuntu系统修改服务器的静态ip地址

    Ubuntu 16.04 #vi /etc/network/interfaces auto lo iface lo inet loopback auto ens3 iface ens3 inet st ...

  10. NodeJS学习视频

    腾讯课堂初级课程 https://ke.qq.com/webcourse/index.html#course_id=196698&term_id=100233129&taid=1064 ...