POJ 3525 Most Distant Point from the Sea [半平面交 二分]
Time Limit: 5000MS | Memory Limit: 65536K | |||
Total Submissions: 5153 | Accepted: 2326 | Special Judge |
Description
The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is natural to ask a question: “Where is the most distant point from the sea?” The answer to this question for Honshu was found in 1996. The most distant point is located in former Usuda Town, Nagano Prefecture, whose distance from the sea is 114.86 km.
In this problem, you are asked to write a program which, given a map of an island, finds the most distant point from the sea in the island, and reports its distance from the sea. In order to simplify the problem, we only consider maps representable by convex polygons.
Input
The input consists of multiple datasets. Each dataset represents a map of an island, which is a convex polygon. The format of a dataset is as follows.
n | ||
x1 | y1 | |
⋮ | ||
xn | yn |
Every input item in a dataset is a non-negative integer. Two input items in a line are separated by a space.
n in the first line is the number of vertices of the polygon, satisfying 3 ≤ n ≤ 100. Subsequent n lines are the x- and y-coordinates of the n vertices. Line segments (xi, yi)–(xi+1, yi+1) (1 ≤ i ≤ n − 1) and the line segment (xn, yn)–(x1, y1) form the border of the polygon in counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. All coordinate values are between 0 and 10000, inclusive.
You can assume that the polygon is simple, that is, its border never crosses or touches itself. As stated above, the given polygon is always a convex one.
The last dataset is followed by a line containing a single zero.
Output
For each dataset in the input, one line containing the distance of the most distant point from the sea should be output. An output line should not contain extra characters such as spaces. The answer should not have an error greater than 0.00001 (10−5). You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.
Sample Input
4
0 0
10000 0
10000 10000
0 10000
3
0 0
10000 0
7000 1000
6
0 40
100 20
250 40
250 70
100 90
0 70
3
0 0
10000 10000
5000 5001
0
Sample Output
5000.000000
494.233641
34.542948
0.353553
Source
题意:
给出一个形状为凸包的岛屿,求岛上离海(即凸包外)最远的点离海的距离有多远
二分多远,然后把凸包缩小这么远,看看此时半平面交有没有交集
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int N=;
const double INF=1e4+;
const double eps=1e-;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
} inline int sgn(double x){
if(abs(x)<eps) return ;
else return x<?-:;
} struct Vector{
double x,y;
Vector(double a=,double b=):x(a),y(b){}
bool operator <(const Vector &a)const{
return sgn(x-a.x)<||(sgn(x-a.x)==&&sgn(y-a.y)<);
}
void print(){printf("%lf %lf\n",x,y);}
};
typedef Vector Point;
Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);}
Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==&&sgn(a.y-b.y)==;}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
double Len(Vector a){return sqrt(Dot(a,a));}
Vector Normal(Vector a){
return Vector(-a.y,a.x);//counterClockwise
}
struct Line{
Point s,t;
Line(){}
Line(Point a,Point b):s(a),t(b){}
};
bool isLSI(Line l1,Line l2){
Vector v=l1.t-l1.s,u=l2.s-l1.s,w=l2.t-l1.s;
return sgn(Cross(v,u))!=sgn(Cross(v,w));
}
Point LI(Line a,Line b){
Vector v=a.s-b.s,v1=a.t-a.s,v2=b.t-b.s;
double t=Cross(v2,v)/Cross(v1,v2);
return a.s+v1*t;
} void iniPolygon(Point p[],int &n,double inf){
n=;
p[++n]=Point(inf,inf);
p[++n]=Point(inf,-inf);
p[++n]=Point(-inf,-inf);
p[++n]=Point(-inf,inf);
}
Point t[N];int tn;
void CutPolygon(Point p[],int &n,Point a,Point b){//get the left of a->b
tn=;
Point c,d;
for(int i=;i<=n;i++){
c=p[i],d=p[i%n+];
if(sgn(Cross(b-a,c-a))>=) t[++tn]=c;
if(isLSI(Line(a,b),Line(c,d)))
t[++tn]=LI(Line(a,b),Line(c,d));
}
n=tn;for(int i=;i<=n;i++) p[i]=t[i];
}
int n,m;
Point p[N],q[N];
Line L[N];
void ChangePolygon(Point p[],int n,double x){
p[n+]=p[];
for(int i=;i<=n;i++){
Vector v=Normal(p[i+]-p[i])*x/Len(p[i+]-p[i]);
L[i]=Line(p[i]+v,p[i+]+v);
}
}
void solve(){
double l=,r=,e=1e-;
while(r-l>e){
double mid=(l+r)/;//printf("hi %lf %lf %lf\n",l,r,mid);
ChangePolygon(p,n,mid);
iniPolygon(q,m,INF);
for(int i=;i<=n;i++) CutPolygon(q,m,L[i].s,L[i].t);
if(m) l=mid;
else r=mid;
}
printf("%lf\n",l);
} int main(int argc, const char * argv[]){
while(true){
n=read();if(n==) break;
for(int i=;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
solve();
}
}
POJ 3525 Most Distant Point from the Sea [半平面交 二分]的更多相关文章
- 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
http://poj.org/problem?id=3525 给出一个凸包,要求凸包内距离所有边的长度的最小值最大的是哪个 思路:二分答案,然后把凸包上的边移动这个距离,做半平面交看是否有解. #in ...
- POJ 3525 Most Distant Point from the Sea (半平面交+二分)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3476 ...
- 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 (半平面交向内推进+二分半径)
题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...
- POJ 3525 Most Distant Point from the Sea 二分+半平面交
题目就是求多变形内部一点. 使得到任意边距离中的最小值最大. 那么我们想一下,可以发现其实求是看一个圆是否能放进这个多边形中. 那么我们就二分这个半径r,然后将多边形的每条边都往内退r距离. 求半平面 ...
- POJ3525 Most Distant Point from the Sea(半平面交)
给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- POJ 3525 半平面交+二分
二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点 #include <cstdio> #include <cstring> # ...
随机推荐
- 重新学习一次javascript;
每次有项目的时候,总觉得自己什么都不会做,然后做的时候又很简单,一会就做完了,啪啪打脸: 每次别人问的时候,我知道怎么做,但是不知道具体原理,觉得瞬间low了: 想要好好的吧基础掌握一下: 这几天空闲 ...
- Dev中GridControl的导出Excel设置
接上篇 Dev中GridControl的GridView 基本样式设置 上图: 导出部分的代码: /// <summary> /// 导出excel /// </summary> ...
- php匹配图片、视频文件、音乐文件的正则表达式
$pattern_video = "/(src)=(\\\?)([\"|']?)([^ \"'>]+\.(swf|flv|mp4|rmvb|avi|mpeg|ra| ...
- Html Mailto标签详细使用方法
http://www.360doc.com/content/09/0805/14/16915_4684377.shtml Html Mailto标签详细使用方法 Html中mailto标签是一个非常实 ...
- 图文教程:在Mac上搭建Titanium的iOS开发环境
http://mobile.51cto.com/web-317170_all.htm 跨平台开发工具Titanium的兴起之路:HTML 5是最大威胁 比较Titanium和PhoneGap两大iOS ...
- js截取字符串的方法
1,slice(a, b) 第一个参数表示起始位置,第二个表示截取到但不包含 关于参数正负问题,只要记住一点:永远不能倒着截取!否则返回空字符串 2,substring(a, b) 第一个参数表示起始 ...
- fread读取文件(二进制文件)
fread()是c库函数,利于移植,使用缓存,效率较read()高. 原型: size_t fread(void *buffer, size_t size, size_t count, FILE * ...
- c#中RGB与int类型之间的转换
Color color = Color.FromArgb(0, 0, 255);int colorInt = ParseRGB(color); --------------------- int Pa ...
- Django_上传图片和模版获取图片
需求: 在Django中,上传图片,存入数据库中的文件的路径,而不是图片本身,也就是说,图片等数据静态文件都可以放到第三方服务器上,我想在把图片保存到Django本地项目中,并可以通过Django自带 ...
- python_如何在列表、字典中筛选数据?
实际问题有哪些? 过滤掉列表[3,9,-1,10.-2......] 中负数 筛选出字典{'li_ming':90,'xiao_hong':60,'li_kang':95,'bei_men':98} ...