POJ3525 Most Distant Point from the Sea(半平面交)
给你一个凸多边形,问在里面距离凸边形最远的点。
方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可。
#pragma warning(disable:4996)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std; #define maxn 2500
#define eps 1e-7 int n; int dcmp(double x){
return (x > eps) - (x < -eps);
} struct Point
{
double x, y;
Point(){}
Point(double _x, double _y) :x(_x), y(_y){}
Point operator + (const Point &b) const{
return Point(x + b.x, y + b.y);
}
Point operator - (const Point &b) const{
return Point(x - b.x, y - b.y);
}
Point operator *(double d) const{
return Point(x*d, y*d);
}
Point operator /(double d) const{
return Point(x / d, y / d);
}
double det(const Point &b) const{
return x*b.y - y*b.x;
}
double dot(const Point &b) const{
return x*b.x + y*b.y;
}
Point rot90(){
return Point(-y, x);
}
Point norm(){
double len=sqrt(this->dot(*this));
return Point(x, y) / len;
}
void read(){
scanf("%lf%lf", &x, &y);
}
}; #define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
#define crossOp(p1,p2,p3) (dcmp(cross(p1,p2,p3))) Point isSS(Point p1, Point p2, Point q1, Point q2){
double a1 = cross(q1, q2, p1), a2 = -cross(q1, q2, p2);
return (p1*a2 + p2*a1) / (a1 + a2);
} struct Border
{
Point p1, p2;
double alpha;
void setAlpha(){
alpha = atan2(p2.y - p1.y, p2.x - p1.x);
}
}; bool operator < (const Border &a,const Border &b) {
int c = dcmp(a.alpha - b.alpha);
if (c != 0) {
return c == 1;
}
else {
return crossOp(b.p1, b.p2, a.p1) > 0;
}
} bool operator == (const Border &a, const Border &b){
return dcmp(a.alpha - b.alpha) == 0;
} Point isBorder(const Border &a, const Border &b){
return isSS(a.p1, a.p2, b.p1, b.p2);
} Border border[maxn];
Border que[maxn];
int qh, qt;
// check函数判断的是新加的半平面和由a,b两个半平面产生的交点的方向,若在半平面的左侧返回True
bool check(const Border &a, const Border &b, const Border &me){
Point is = isBorder(a, b);
return crossOp(me.p1, me.p2, is) > 0;
} bool convexIntersection()
{
qh = qt = 0;
sort(border, border + n);
n = unique(border, border + n) - border;
for (int i = 0; i < n; i++){
Border cur = border[i];
while (qh + 1 < qt&&!check(que[qt - 2], que[qt - 1], cur)) --qt;
while (qh + 1 < qt&&!check(que[qh], que[qh + 1], cur)) ++qh;
que[qt++] = cur;
}
while (qh + 1 < qt&&!check(que[qt - 2], que[qt - 1], que[qh])) --qt;
while (qh + 1 < qt&&!check(que[qh], que[qh + 1], que[qt - 1])) ++qh;
return qt - qh > 2;
} Point ps[maxn]; bool judge(double x)
{
for (int i = 0; i < n; i++){
border[i].p1 = ps[i];
border[i].p2 = ps[(i + 1) % n];
}
for (int i = 0; i < n; i++){
Point vec = border[i].p2 - border[i].p1;
vec=vec.rot90().norm();
vec = vec*x;
border[i].p1 = border[i].p1 + vec;
border[i].p2 = border[i].p2 + vec;
border[i].setAlpha();
}
return convexIntersection();
} int main()
{
while (cin>>n&&n)
{
for (int i = 0; i < n; i++){
ps[i].read();
}
double l=0, r=100000000;
while (dcmp(r-l)>0){
double mid = (l + r) / 2;
if (judge(mid)) l = mid;
else r = mid;
}
printf("%.6lf\n", l);
}
return 0;
}
POJ3525 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 (半平面交)
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
题目描述: vjudge POJ 题解: 二分答案+半平面交. 半径范围在0到5000之间二分,每次取$mid$然后平移所有直线,判断半平面交面积是否为零. 我的eps值取的是$10^{-12}$,3 ...
- 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(直线平移、半平面交)
按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
随机推荐
- 【javascript】随手记代码
//js实现的当前界面的刷新.前进.后退 <input type="button" value="刷新" onclick="window.loc ...
- WPF之旅(二)- XAML
什么是XAML XAML(Extensible Application Markup Lanaguage的简写,发音“zammel”)是用于实例化.NET对象的标记语言.尽管XAML是一种可以用于诸多 ...
- ANT编译build.xml
一,体验ant就像每个语言都有HelloWorld一样,一个最简单的应用能让人感受一下Ant1,首先你要知道你要干什么,我现在想做的事情是:编写一些程序编译它们把它打包成jar包把他们放在应该放置的地 ...
- android开发中经常遇到的问题汇总
大家都在为项目开发成功而喜悦,但可不知成功的路上是会经常出错的,下面是我碰到的一些错误集合! [错误信息] [2011-01-19 16:39:10 - ApiDemos] WARNING: Appl ...
- C#.Net 图片处理大全
C# How to: Image filtering by directly manipulating Pixel ARGB values C# How to: Image filtering imp ...
- ASP.NET MVC如何实现自定义验证(服务端验证+客户端验证)
ASP.NET MVC通过Model验证帮助我们很容易的实现对数据的验证,在默认的情况下,基于ValidationAttribute的声明是验证被使用,我们只需 要将相应的ValidationAttr ...
- js 获取字符串中最后一个斜杠后面的内容
var str = "/asdasf/asfaewf/agaegr/trer/rhh"; var index = str .lastIndexOf("\/"); ...
- mysql 任意连接
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话. mysql> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDE ...
- matlab 函数的编写与调用
matlab中写个函数,在主程序中调用该函数的方法 跟其它的编程语言都一样,但是子函数与主函数要存于不同的文件中,文件名就是函数名字.文件必须保存在current directory中,才能调用. 函 ...
- Mysql的相关命令
1.登录服务器 mysql -h host -u user -p mysql -h host -u user -p 数据库 2.使用SHOW语句找出服务器上当前存在什么数据库:mysql> SH ...