考虑怎样的点满足条件。设其为(xp,yp),则要满足(x0-xp,y0-yp)×(x1-xp,y1-yp)<=(xi-xp,yi-yp)×(xi+1-xp,yi+1-yp)对任意i成立。拆开式子,有(x0-xp)*(y1-yp)-(y0-yp)*(x1-xp)<=(xi-xp)*(yi+1-yp)-(yi-yp)*(xi+1-xp),也即x0y1-x0yp-xpy1-y0x1+y0xp+ypx1<=xiyi+1-xiyp-xpyi+1-yixi+1+yixp+ypxi+1。移项,得(y0-y1+yi+1-yi)xp+(x1-x0+xi-xi+1)yp<=xiyi+1-yixi+1-x0y1+y0x1。一长串乱七八糟的限制都是对(xp,yp)这个二元组的,半平面交即可。当然再套上一个凸包自身的限制。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
#define vector point
#define double long double
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int gcd(int n,int m){return m==?n:gcd(m,n%m);}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
const double eps=1E-;
struct point
{
double x,y;
vector operator +(const vector&a) const
{
return (vector){x+a.x,y+a.y};
}
vector operator -(const vector&a) const
{
return (vector){x-a.x,y-a.y};
}
double operator *(const vector&a) const
{
return x*a.y-y*a.x;
}
vector operator *(const double&a) const
{
return (vector){x*a,y*a};
}
}a[N];
struct line
{
point a;vector p;
bool operator <(const line&a) const
{
return atan2(p.x,p.y)>atan2(a.p.x,a.p.y);
}
}b[N<<];
int n,m,head,tail;
point p[N<<];
line q[N<<];
double area;
bool onright(point a,line p)
{
return (a-p.a)*p.p>=;
}
point cross(line a,line b)
{
return a.a+a.p*((b.p*(b.a-a.a))/(b.p*a.p));
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj4445.in","r",stdin);
freopen("bzoj4445.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
n=read();
for (int i=;i<n;i++) a[i].x=read(),a[i].y=read();
for (int i=;i<n;i++) area+=a[i]*a[(i+)%n];
for (int i=;i<n;i++) m++,b[m].a=a[i],b[m].p=a[(i+)%n]-a[i];
for (int i=;i<n;i++)
{
double A=(a[].y-a[].y+a[(i+)%n].y-a[i].y),B=(a[].x-a[].x+a[i].x-a[(i+)%n].x),C=(a[i]*a[(i+)%n]-a[]*a[]);
m++;b[m].p=(vector){-B,A};
if (fabs(B)>0.5) b[m].a=(point){,C/B};
else b[m].a=(point){C/A,};
}
sort(b+,b+m+);
head=tail=;q[]=b[];
for (int i=;i<=m;i++)
{
while (head<tail&&onright(p[tail],b[i])) tail--;
while (head<tail&&onright(p[head+],b[i])) head++;
q[++tail]=b[i];
if (fabs(q[tail].p*q[tail-].p)<eps)
{
tail--;
if (onright(q[tail].a,b[i])) q[tail]=b[i];
}
if (head<tail) p[tail]=cross(q[tail],q[tail-]);
}
while (head<tail&&onright(p[tail],q[head])) tail--;
p[head]=cross(q[head],q[tail]);
double area2=;
for (int i=head;i<tail;i++)
area2+=p[i]*p[i+];area2+=p[tail]*p[head];
#undef double
printf("%.4f",(double)(area2/area));
return ;
}