# [POJ3525]Most Distant Point from the Sea（二分+半平面交）

## 代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 1005

const double inf=1e9;
const double pi=acos(-1.0);
const double eps=1e-9;
int dcmp(double x)
{
if (x<=eps&&x>=-eps) return 0;
return (x>0)?1:-1;
}
struct Vector
{
double x,y;
Vector(double X=0,double Y=0)
{
x=X,y=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 p) {return Vector(a.x*p,a.y*p);}

int n,cnt,ncnt;
double x,y,Max,ans;
Point p[N],poly[N],npoly[N];

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));
}
{
}
bool insLS(Point A,Point B,Point C,Point D)
{
Vector v=B-A,w=C-A,u=D-A;
return dcmp(Cross(v,w))!=dcmp(Cross(v,u));
}
Point GLI(Point P,Vector v,Point Q,Vector w)
{
Vector u=P-Q;
double t=Cross(w,u)/Cross(v,w);
return P+v*t;
}
void init()
{
cnt=0;
poly[++cnt]=Point(inf,inf);
poly[++cnt]=Point(-inf,inf);
poly[++cnt]=Point(-inf,-inf);
poly[++cnt]=Point(inf,-inf);
}
void halfp(Point A,Point B)
{
ncnt=0;
Point C,D;
for (int i=1;i<=cnt;++i)
{
C=poly[i%cnt+1];
D=poly[(i+1)%cnt+1];
if (dcmp(Cross(B-A,C-A))>=0)
npoly[++ncnt]=C;
if (insLS(A,B,C,D))
npoly[++ncnt]=GLI(A,B-A,C,D-C);
}
cnt=ncnt;
for (int i=1;i<=cnt;++i)
poly[i]=npoly[i];
}
bool check(double mid)
{
Point A,B,C,D;
Vector v,w;
init();
for (int i=1;i<=n;++i)
{
A=p[i%n+1];
B=p[(i+1)%n+1];
v=B-A;
w=rotate(B-A,pi/2.0);
w=w*(mid/Len(w));
C=A+w;
D=C+v;
halfp(C,D);
}
if (cnt) return true;
else return false;
}
double find()
{
double l=0,r=Max,mid,ans;
while (dcmp(r-l)>0)
{
mid=(l+r)/2.0;
if (check(mid)) ans=mid,l=mid;
else r=mid;
}
return ans;
}
int main()
{
while (~scanf("%d",&n))
{
if (!n) break;
Max=0;
for (int i=1;i<=n;++i)
{
scanf("%lf%lf",&x,&y);
Max=max(Max,x);Max=max(Max,y);
p[i]=Point(x,y);
}
ans=find();
printf("%.6lf\n",ans);
}
return 0;
}