LA3890 Most Distant Point from the Sea
题意
分析
可以二分答案,检验就用半平面交,如果平面非空则合法。
时间复杂度\(O(T n \log^2 n)\)
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
{
data=data*10+ch-'0';
ch=getchar();
}
return data*w;
}
template<class T>T read(T&x)
{
return x=read<T>();
}
using namespace std;
typedef long long ll;
struct Point
{
double x,y;
Point(double x=0,double y=0)
:x(x),y(y){}
};
typedef Point Vector;
Vector operator+(co Vector&A,co Vector&B)
{
return Vector(A.x+B.x,A.y+B.y);
}
Vector operator-(co Vector&A,co Vector&B)
{
return Vector(A.x-B.x,A.y-B.y);
}
Vector operator*(co Vector&A,double p)
{
return Vector(A.x*p,A.y*p);
}
Vector operator/(co Vector&A,double p)
{
return Vector(A.x/p,A.y/p);
}
double Dot(co Vector&A,co Vector&B)
{
return A.x*B.x+A.y*B.y;
}
double Cross(co Vector&A,co Vector&B)
{
return A.x*B.y-A.y*B.x;
}
double Length(co Vector&A)
{
return sqrt(Dot(A,A));
}
Vector Normal(co Vector&A)
{
double L=Length(A);
return Vector(-A.y/L,A.x/L);
}
double PolygonArea(vector<Point> p)
{
int n=p.size();
double area=0;
for(int i=1;i<n-1;++i)
area+=Cross(p[i]-p[0],p[i+1]-p[0]);
return area/2;
}
struct Line
{
Point P;
Vector v;
Line(Point P=0,Vector v=0)
:P(P),v(v){}
double angle()co
{
return atan2(v.y,v.x);
}
bool operator<(co Line&rhs)co
{
return angle()<rhs.angle();
}
};
bool OnLeft(co Line&L,co Point&p)
{
return Cross(L.v,p-L.P)>0;
}
Point LineLineIntersection(co Line&a,co Line&b)
{
Vector u=a.P-b.P;
double t=Cross(b.v,u)/Cross(a.v,b.v);
return a.P+a.v*t;
}
co double INF=1e8;
co double eps=1e-6;
vector<Point>HalfplaneIntersection(vector<Line>L)
{
int n=L.size();
sort(L.begin(),L.end());
int first,last;
vector<Point>p(n);
vector<Line>q(n);
vector<Point>ans;
q[first=last=0]=L[0];
for(int i=1;i<n;++i)
{
while(first<last&&!OnLeft(L[i],p[last-1]))
--last;
while(first<last&&!OnLeft(L[i],p[first]))
++first;
q[++last]=L[i];
if(fabs(Cross(q[last].v,q[last-1].v))<eps)
{
--last;
if(OnLeft(q[last],L[i].P))
q[last]=L[i];
}
if(first<last)
p[last-1]=LineLineIntersection(q[last-1],q[last]);
}
while(first<last&&!OnLeft(q[first],p[last-1]))
--last;
if(last-first<=1)
return ans;
p[last]=LineLineIntersection(q[last],q[first]);
for(int i=first;i<=last;++i)
ans.push_back(p[i]);
return ans;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int n;
while(read(n))
{
vector<Vector>p,v,normal;
for(int i=0;i<n;++i)
p.push_back(Point(read<int>(),read<int>()));
if(PolygonArea(p)<0)
reverse(p.begin(),p.end());
for(int i=0;i<n;++i)
{
v.push_back(p[(i+1)%n]-p[i]);
normal.push_back(Normal(v[i]));
}
double left=0,right=2e4;
while(right-left>eps)
{
vector<Line>L;
double mid=(left+right)/2;
for(int i=0;i<n;++i)
L.push_back(Line(p[i]+normal[i]*mid,v[i]));
vector<Point>poly=HalfplaneIntersection(L);
if(poly.empty())
right=mid;
else
left=mid;
}
printf("%.6lf\n",left);
}
return 0;
}
LA3890 Most Distant Point from the Sea的更多相关文章
- 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 Most Distant Point from the Sea (半平面交+二分)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3476 ...
- 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 ...
- 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)
按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
随机推荐
- Java:判断字符串是否为数字的五种方法
Java:判断字符串是否为数字的五种方法 //方法一:用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = str. ...
- The revocation function was unable to check revocation for the certificate
https://stackoverflow.com/questions/45556189/git-the-revocation-function-was-unable-to-check-revocat ...
- static变量的作用
在C语言中,关键字static的意思是静态的,有3个明显的作用: 1. 在函数体内,静态变量具有记忆作用,即一个被声明为静态的变量在这一函数被调用的过程中其值维持不变. 2. 在模块内(但在函数体外) ...
- Java Swing窗体小工具实例 - 原创
Java Swing窗体小工具实例 1.本地webserice发布,代码如下: 1.1 JdkWebService.java package server; import java.net.InetA ...
- Android各种屏幕分辨率(VGA、HVGA、QVGA、WQVGA、WVGA、FWVGA) 详解 .
http://blog.csdn.net/lucherr/article/details/8498400 看资料的时候经常看到各种VGA,全都混了,无奈,找了些资料总结了下,分享给大家: 这些术语都是 ...
- 用HyperMesh(7.0)手工修改网格
检查网格质量并修改 2D->qulifyindex:其中View/Edit/Optimize工具栏功能常用,尤其是Edit页中的Place Node,可以动态地拖动节点并观察单元质量是否符合要求 ...
- JavaScript tips —— 搞定闰年
前言 处理时间时,常常要考虑用户的输入是否合法,其中一个很典型的场景就是平闰年的判断,网上其实有很多类似的算法,但是其实不必那么麻烦,下面我讲讲的我的思路. 规则 公元年数可被4整除为闰年,但是整百( ...
- Eclipse下建立简单JNI程序实现返回double类型
在Eclipse下生成时要注意,由于通常是在package里面添加类,而非像单独建立工程时独立添加,所以,在编译的时候,都需要进入包所在的文件夹, javac 包名.类名 这样的形式来编译,同理,ja ...
- mybatis 批量修改接口的几种实现方式
-----------------我也是有上线的--------------我也是有上线的------------我也是有上线的---------------我也是有上线的-------------- ...
- MongoDB 可视化管理工具 MongoCola-1.1.0 测试版发布
首先,感谢大家对于本工具的支持. 经过一周的努力,最新版的工具测试版出炉了,这个版本是一个很重要的版本. 为什么说这个版本重要?以前的工具,只支持一个视图窗口,也就是说了,一次只能看一个数据集的数据. ...