# [bzoj1038][ZJOI2008]瞭望塔

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define MN 300
#define eps 1e-10
#define INF 1e17
using namespace std;
{
int x = 0 , f = 1; char ch = getchar();
while(ch < '0' || ch > '9'){ if(ch == '-') f = -1;  ch = getchar();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}

struct P{
double x,y;
P(double _x=0,double _y=0):x(_x),y(_y){}
P operator+(P b){return P(x+b.x,y+b.y);}
P operator-(P b){return P(x-b.x,y-b.y);}
P operator*(double b){return P(x*b,y*b);}
double operator^(P b){return x*b.y-b.x*y;}
}p[MN+5];

struct L{
P p,v;double slop;
L(){}
L(P x,P y):p(x),v(y){slop=atan2(y.y,y.x);}
P operator*(L b){P u=p-b.p;double t=(b.v^u)/(v^b.v);return p+v*t;}
bool Left(P b){return (v^(b-p))>eps;}
bool operator<(const L&b)const{return slop<b.slop;}
}q[MN+5],s[MN+5];

int n,top,tail;
double x[MN+5],y[MN+5],ans=INF;

void solve()
{
q[top=tail=1]=s[1];
for(int i=2;i<=n+3;i++)
{
while(top>tail&&!s[i].Left(p[top]))--top;
while(top>tail&&!s[i].Left(p[tail+1])) ++tail;
if(fabs(s[i].slop-q[top].slop)<eps)
q[top]=s[i].Left(q[top].p)?q[top]:s[i];
else q[++top]=s[i];
p[top]=q[top]*q[top-1];
}
while(top>tail&&!q[tail].Left(p[top])) --top;
}

int main()
{
for(int i=1;i<=n;i++)scanf("%lf",&x[i]);
for(int i=1;i<=n;i++)scanf("%lf",&y[i]);
for(int i=1;i<n;i++)s[i]=L(P(x[i],y[i]),P(x[i+1]-x[i],y[i+1]-y[i]));
s[n]=L(P(x[n],INF),P(-INF*2,0));
s[n+1]=L(P(x[1],-INF),P(INF*2,0));
s[n+2]=L(P(x[1],INF),P(0,-2*INF));
s[n+3]=L(P(x[n],-INF),P(0,INF*2));
sort(s+1,s+n+4);
solve();p[tail]=q[tail]*q[top];int j;
for(int i=tail;i<=top;i++)
{
if(p[i].x<=x[1]+eps&&p[i].x+eps>=x[n]) continue;
for(j=1;j<n;j++) if(x[j]<=p[i].x+eps&&p[i].x+eps<=x[j+1]) break;
P t=L(P(x[j],y[j]),P(x[j+1]-x[j],y[j+1]-y[j]))*L(P(p[i].x,-INF),P(0,2*INF));
ans=min(ans,p[i].y-t.y);
}
for(int i=1;i<=n;i++)
{
for(j=tail;j<top;j++) if(p[j].x<=x[i]+eps&&p[j+1].x>=x[i]+eps) break;
P t=L(p[j],p[j+1]-p[j])*L(P(x[i],-INF),P(0,2*INF));
ans=min(ans,t.y-y[i]);
}
printf("%.3lf",ans);
return 0;
}

posted @ 2017-04-05 18:51  FallDream  阅读(200)  评论(0编辑  收藏  举报