Half-plane intersection.
The half plane refers to the left side of a straight line (and I don't know if it's right)
Semi-planar intersection refers to a lot of half-plane public parts.
The solution of this problem must be in the half-plane intersection of each line.
And the Watchtower may only be at the inflection point of the dots or the half-plane intersection.
Find out half-plane intersection, enumeration can be.
#include <cstdio>#include<algorithm>#include<cstring>#include<cmath>#defineEPS 1e-7using namespacestd;Const intMAXN = -+Ten;structPoint {Doublex, y; }p[maxn],t;structLine {Doublek,b; voidInit (Point p1,point p2) {k= (P1.Y-P2.Y)/(p1.x-p2.x); b=p2.y-k*p2.x; }}L[MAXN],S[MAXN];intn,sp;Doubleres=1e11;BOOLcmp (line X,line y) {if(ABS (X.K-Y.K) <eps)returnx.b<y.b; returnx.k<Y.K;} Point Inter (line L1,line L2) {Point res; Res.x= (l2.b-l1.b)/(l1.k-L2.K); Res.y=l1.k*res.x+l1.b; returnRes;}voidpush (line l) { while(sp>=2&& Inter (s[sp],l). x < Inter (s[sp-1],S[SP]). x) sp--; s[++sp]=l;}DoubleFDoublex) {Doubleres=0; for(intI=1; i<=sp;i++) Res=max (res,s[i].k*x+s[i].b); returnRes;}DoubleGDoublex) {inti; for(i=n;i&&x<p[i].x;i--); returnp[i].y+ (x-p[i].x)/(p[i+1].x-p[i].x) * (p[i+1].y-p[i].y); }intMain () {scanf ("%d",&N); for(intI=1; i<=n;i++) scanf ("%LF",&p[i].x); for(intI=1; i<=n;i++) scanf ("%LF",&p[i].y); for(intI=1; i<n;i++) L[i].init (p[i],p[i+1]); Sort (L+1, L +n,cmp); for(intI=1; i<n;i++)if(i==n-1|| ABS (l[i].k-l[i+1].K) >EPS) push (L[i]); for(intI=1; i<=n;i++) Res=min (Res,f (p[i].x)-p[i].y); for(intI=1; i<sp;i++) {T=inter (s[i],s[i+1]); Res=min (res,t.y-g (t.x)); } printf ("%.3lf\n", RES); return 0;}
1038: [ZJOI2008] Lookout tower