poj3525 Most Distant Point from the Sea
题目描述:
题解:
二分答案+半平面交。
半径范围在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的更多相关文章
- POJ3525 Most Distant Point from the Sea(半平面交)
给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...
- POJ 3525 Most Distant Point from the Sea (半平面交+二分)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3476 ...
- POJ 3525 Most Distant Point from the Sea [半平面交 二分]
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5153 ...
- LA 3890 Most Distant Point from the Sea(半平面交)
Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...
- 【POJ】【3525】Most Distant Point from the Sea
二分+计算几何/半平面交 半平面交的学习戳这里:http://blog.csdn.net/accry/article/details/6070621 然而这题是要二分长度r……用每条直线的距离为r的平 ...
- 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 ...
- POJ3525-Most Distant Point from the Sea(二分+半平面交)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3955 ...
- 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 ...
- POJ3525:Most Distant Point from the Sea(二分+半平面交)
pro:给定凸多边形,求凸多边形内的点到最近边界的最远距离. sol:显然是二分一个圆,使得圆和凸多边形不相交,但是这样很难实现. 由于是凸多边形,我们可以把二分圆转化为二分凸多边形的移动. 如果每一 ...
随机推荐
- HTML5新标签介绍
一.Datalist 标签 <input list="browsers"> <datalist id="browsers"> < ...
- 洛谷 P2895 [USACO08FEB]流星雨Meteor Shower 解题报告
一起来看流星雨吧(话说我还没看到过流星雨呢) 题目 Problem 小A则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽,届时将会对它撞到的一 ...
- 用Open Live Writer写博体验
感觉还蛮方便的--openlivewriter第一博!
- Linux下无法挂载U盘
大概的错误信息是这样的: Error mounting /dev/sdb4 at /media/xxx/xx: Command-line`mount -t "ntfs" -o&qu ...
- github 新建一个分支
我能说今天在github上新建分支的时候懵逼了半天吗..为了下次不再懵逼,还是在这里记录一下吧.. 进入你的项目---code---Branch----点击那个倒三角-----你会发现一个输入框(这是 ...
- 机器学习框架ML.NET学习笔记【5】多元分类之手写数字识别(续)
一.概述 上一篇文章我们利用ML.NET的多元分类算法实现了一个手写数字识别的例子,这个例子存在一个问题,就是输入的数据是预处理过的,很不直观,这次我们要直接通过图片来进行学习和判断.思路很简单,就是 ...
- mysql非常全的和完整的总结
(1)数据类型 类型 备注 tinyint/smallint/mediumint/int/bigint 1B/2B/3B/4B/8B float/double 单精度/双精度浮点型 decimal 不 ...
- VS连接Access数据库--连接字符串及执行查询语句的方法(增删改查,用户名查重,根据用户获取密码查询)
ACCESS数据的连接及语句执行操作,不难,久不用会生疏,每次都要找资料,干脆自己整理下,记录下来,需要的时候,直接查看,提高效率.也供初学者参考 1.连接字符串 public static stri ...
- this的那点事
对于很多初学者,this总是搞得我们晕头转向. 现在,我就简单的总结一下关于this的那点事. this在函数定义时经常是不能确定的,只有在函数执行的时候才能最终确定this的归属.this总是指向最 ...
- mui轮播图
轮播组件是mui提供的一个核心组件,在该核心组件基础上,衍生出了图片轮播.可拖动式图文表格.可拖动式选项卡.左右滑动9宫格等组件,这些组件有较多共同点.Dom构造: <div class=&qu ...