poj 3525 Most Distant Point from the Sea(半平面交+二分)

原创 2017年01月03日 18:57:27

Most Distant Point from the Sea
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 5136   Accepted: 2323   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 (xiyi)–(xi+1yi+1) (1 ≤ i ≤ n − 1) and the line segment (xnyn)–(x1y1) 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

[Submit]   [Go Back]   [Status]   [Discuss]


题目大意:求凸包中的点到凸包边界的最远距离,即凸多边形的最大内切圆。

题解:二分+半平面交。

每次二分一个长度,然后让凸多边形的每条边向内缩,以缩完后的边界做半平面交,如果不存在公共区域或者公共区域为一个点,则说明长度大了或正好,继续二分即可。

主要是内缩比较难搞,我是把相邻两点构成的向量存储下来,然后按照法向量的方向平移得到新的向量,再进行半平面交的。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define N 103
#define eps 1e-7
#define inf 1e9
using namespace std;
struct vector {
	double x,y;
	vector (double X=0,double Y=0){
		x=X,y=Y;
	}
}a[N],p[N],tmp[N],b[N];
struct data
{
	vector a,b;
}line[N];
int m,n;
double pi=acos(-1.0);
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 t){return vector (a.x*t,a.y*t);}
vector operator /(vector a,double t){return vector (a.x/t,a.y/t);}
void init()
{
	m=0;
	p[m++]=point(inf,inf);
	p[m++]=point(-inf,inf);
	p[m++]=point(-inf,-inf);
	p[m++]=point(inf,-inf);
}
int dcmp(double x)
{
	if (fabs(x)<eps) return 0;
	return x<0?-1:1;
}
double cross(vector a,vector b)
{
	return a.x*b.y-a.y*b.x;
}
point glt(point a,point a1,point b,point b1)
{
	vector v=a1-a; vector w=b1-b;
	vector u=a-b;
	double t=cross(w,u)/cross(v,w);
	return a+v*t;
}
void cut(point a,point b)
{
	int cnt=0;
	memset(tmp,0,sizeof(tmp));
	for (int i=0;i<m;i++){
		double c=cross(b-a,p[i]-a);
		double d=cross(b-a,p[(i+1)%m]-a);
		if (dcmp(c)<=0) tmp[cnt++]=p[i];
		if (dcmp(c)*dcmp(d)<0)
		 tmp[cnt++]=glt(a,b,p[i],p[(i+1)%m]);
	}
	m=cnt;
	for (int i=0;i<cnt;i++) p[i]=tmp[i];
}
vector rotate(vector a,double rad)
{
	return vector (a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
double len(vector v)
{
	return sqrt(v.x*v.x+v.y*v.y);
}
bool pd(double x)
{
	for (int i=2;i<=n+1;i++){
		vector v=b[i]-b[i-1];
		vector u=rotate(v,pi/2)/len(v);
		u=u*x;	
		line[i-1].a=v+u+b[i-1];
		line[i-1].b=line[i-1].a-v;
		int t=0;
	}
	init();
	for (int i=1;i<=n;i++){
		cut(line[i].a,line[i].b);
		if (!m) return true;
	}
	if (m==1) return true;
	return false;
}
int main()
{
	freopen("a.in","r",stdin);
	while (true){
		scanf("%d",&n);
		if (!n) break;
		for (int i=1;i<=n;i++) scanf("%lf%lf",&b[i].x,&b[i].y);
		b[n+1]=b[1];
		double l=0; double r=10000; double ans=0;
		while (r-l>eps){
			double mid=(l+r)/2;
			if (pd(mid)) ans=mid,r=mid-eps;
			else l=mid+eps;
		}
		printf("%.6lf\n",ans);
	}
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3525 Most Distant Point from the Sea(半平面交+二分)

转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove 题目:一个多边形,求出到边...

POJ 3525 Most Distant Point from the Sea (半平面交+二分求最大内切圆)

Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total...

POJ 3525 Most Distant Point from the Sea 二分+内推+半平面交

题目描述:http://poj.org/problem?id=3525  解题思路:
  • f_cpp
  • f_cpp
  • 2014年11月19日 12:28
  • 154

【二分+半平面交】 POJ 3525 Most Distant Point from the Sea

套上计算几何的模板。。。然后二分搞一下。。。

POJ 3525 Most Distant Point from the Sea 二分+半平面交

链接:http://poj.org/problem?id=3525 题意:给一个凸多边形的海岛,寻找海岛之中距离海边距离最长的一个点的距离。 思路:求凸多边形的最大内切圆。做法是二分半径加半平面交,将...

Poj 3525 Most Distant Point from the Sea (二分+半平面求交)

题目链接:http://poj.org/problem?id=3525 题意:多边形内可以容纳的最大的圆的半径。 思路:半平面交+二分,将多边形的每条边向内平移r,二分r,判断是否有位置可以放置圆...

POJ 3525 || Most Distant Point from the Sea (凸包求最大内接圆,半平面交内推r

题目在问这样一个问题:给定一个凸多边形,找到其中的一个点,使得其到每条边的距离最小值最大,输出这个距离。 其实就是在问你,这个多边形中最大的一个内切圆有多大。 怎么做呢?如果我们事先知道一...
  • FXXKI
  • FXXKI
  • 2015年05月12日 21:08
  • 502

POJ 3525 Most Distant Point from the Sea 半平面交判多边形存在

问凸多边形中某点到边界距离最远有多大。 最优值问题转化判定性问题。 判定就很好判定啦,将凸多边形往内缩答案,如果半平面交有解那么答案就是允许的。 #define FOR(i,j,k) for(i...

poj3525Most Distant Point from the Sea【半平面交求到凸多边形边界最远距离】

Language: Default Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: ...

POJ 3525 Most Distant Point from the Sea (半平面交求多边形中可以放入最大的圆的半径)

半平面交求多边形中可以放入最大的圆的半径.
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:poj 3525 Most Distant Point from the Sea(半平面交+二分)
举报原因:
原因补充:

(最多只允许输入30个字)