#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1005;
const double eps=1e-12;
double ans=1e10;
struct vec{
double x,y;
vec(double x=0,double y=0):x(x),y(y){}
vec operator-(vec& a){
return vec(x-a.x,y-a.y);
}
vec operator+(vec&a){
return vec(x+a.x,y+a.y);
}
}po[maxn],g[maxn];
vec operator*(vec a,double t){return vec(a.x*t,a.y*t);}
double cross(vec a,vec b){return a.x*b.y-b.x*a.y;}
struct lin{
vec p,v;//p是直线上一个点，v是方向向量
double ang;//ang是斜率;
lin(){}
lin(vec p,vec v):p(p),v(v){ang=atan2(v.y,v.x);}
bool operator<(const lin&a)const{
return ang<a.ang;
}
}ll[maxn],q[maxn],bb,cc;
bool onl(lin L,vec p){
return cross(L.v,p-L.p)>0;
}
vec qj(lin a,lin b){
vec u=a.p-b.p;
double t=cross(b.v,u)/cross(a.v,b.v);
return a.v*t+a.p;
}
void halfj(){
sort(ll,ll+n);
for(int i=1;i<n;++i){
q[++tail]=ll[i];
if(fabs(cross(q[tail].v,q[tail-1].v))<eps){
--tail;if(onl(q[tail],ll[i].p))q[tail]=ll[i];
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;++i){
scanf("%lf",&po[i].x);
}
for(int i=1;i<=n;++i){
scanf("%lf",&po[i].y);
}
po[0].x=po[1].x;po[0].y=100001;
po[n+1].x=po[n].x;po[n+1].y=100001;
for(int i=0;i<=n;++i){
ll[i]=lin(po[i],po[i+1]-po[i]);
}
n+=1;
halfj();
for(int k=0;k<tail;++k)
for(int i=1;i<n-1;++i){
vec tmp;tmp.x=g[k].x;tmp.y=-1;
if(g[k].x>=po[i].x&&g[k].x<=po[i+1].x){
cc=lin(po[i],po[i+1]-po[i]);
bb=lin(tmp,g[k]-tmp);
ans=min(ans,g[k].y-qj(cc,bb).y);
}
}
for(int k=1;k<=n-1;++k)
for(int i=0;i<tail-1;++i){
vec tmp;tmp.x=po[k].x;tmp.y=-1;
if(po[k].x>=g[i].x&&po[k].x<=g[i+1].x){
cc=lin(g[i],g[i+1]-g[i]);
bb=lin(tmp,po[k]-tmp);
ans=min(ans,qj(cc,bb).y-po[k].y);
}
}
printf("%.3lf",ans);
return 0;
} 

posted on 2018-03-24 16:15  湮灭之瞳  阅读(88)  评论(0编辑  收藏  举报