POJ 3525 Most distant point to the sea (half plane and two points) _ two points

Source: Internet
Author: User
Tags cos sin

Most distant point from the sea
Time Limit: 5000MS Memory Limit: 65536K
Total submissions: 5136 accepted: 2323 Special Judge

Description

The main land of the Japan called Honshu is a island surrounded by the sea. In such an island, it's natural to ask a question: "Where's the most distant point from the sea?" The answer to this question for Honshu is found in 1996. The most distant point are located in former Usuda Town, Nagano Prefecture, whose distance to the ' sea ' is 114.86 km.

In this problem, your are asked to write a program which, given a map of a island, finds the most EA in the island, and reports its distance to the sea. In order to simplify the problem, we have consider maps representable by convex polygons.

Input

The input consists of multiple datasets. Each dataset represents a map of the 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 ' The ' of the # 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. This is the inside of the "polygon in the" the left of their directions of the segments. All coordinate values are between 0 and 10000, inclusive.

You can assume this polygon is simple, which is, its border never crosses or touches itself. As stated above, the given polygon is always a convex one.

The last dataset was followed by a line containing a single zero.

Output

For each dataset in the input, one line containing the distance of the the most distant point from the sea should to be output. An output line should not contain extra characters such as spaces. The answer should not have a error greater than 0.00001 (10−5). You could output any number of digits to the decimal point, provided this 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/
100 20< c11/>250
0
3
0 0
10000 10000
5000 5001
0

Sample Output

5000.000000
494.233641
34.542948
0.353553

Source Japan 2007

[Submit] [Go back] [Status] [discuss]

The main idea is to find the farthest distance from the point of convex package to the convex boundary, that is, the maximum incircle of convex polygon.

Solving: Two points + half plane intersection.

Each time two minutes a length, and then let the convex polygon of each edge inward contraction, to the boundary after the contraction to do half plane intersection, if there is no public area or public area for a point, then the length of a large or just, continue to two points.

Mainly internal shrinkage is more difficult to do, I am the adjacent two points of the vector storage, and then in the direction of the normal vector translation to get a new vector, and then a half plane intersection.

#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <
Cmath> #define N #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", &AMP;B[I].X,&AMP;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); }
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.