The first half-plane intersection, and then the tower of the place must be at the intersection of the half-plane crossing or at the intersection of the ground segment.
#include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <iostream > #include <algorithm> #include <cctype> #define REP (i, L, R) for (int i=l; i<=r; i++) #define MAXN 1009#def Ine Linf 1e15using namespace Std;inline int read () {int x=0, f=1; char Ch=getchar (); while (!isdigit (CH)) {if (ch== '-') f=-1 ; Ch=getchar ();} while (IsDigit (CH)) x=x*10+ch-' 0 ', Ch=getchar (); return x*f;} struct p{double x, y;} P[maxn], p2[maxn];struct line{p A, b; double ang;} G[MAXN], L[MAXN], A[MAXN], Q[MAXN]; P operator-(p a, p B) {return (p) {a.x-b.x, a.y-b.y};} Double operator * (p a, p b) {return a.x*b.y-a.y*b.x;} BOOL Operator < (line A, line B) {if (A.ang==b.ang) return (A.B-A.A) * (B.A-A.A) >0; return A.ang<b.ang;} BOOL operator < (p A, p b) {return a.x<b.x;} Inline P Inter (line A, line B) {double k1= (b.b-a.a) * (A.B-A.A), k2= (A.B-A.A) * (B.A-A.A), t=k2/(K1+K2); return (P) {b.a.x+t* ( b.b.x-b.a.x), b.a.y+t* (B.B.Y-B.A.Y)};} inline bool Jud (line A, line B, LinE v) {return (Inter (A, b)-v.a) * (V.B-V.A) >0;} int n, m, L, R, cnt;double ans;int main () {n=read (); M=n-1;rep (i, 1, N) p[i].x=read (); Rep (i, 1, N) p[i].y=read (); Rep (I, 1, m) G[i].a=p[i], G[i].b=p[i+1];rep (i, 1, m) l[i]=g[i], l[i].ang=atan2 (L[I].B.Y-L[I].A.Y, l[i].b.x-l[i].a.x); sort (l+1, l +M+1); a[++cnt]=l[1]; Rep (I, 2, M) A[a[cnt].ang!=l[i].ang ++cnt:cnt]=l[i]; L=1, r=0, q[++r]=a[1], Q[++r]=a[2];rep (i, 3, CNT) {while (L<r && Jud (Q[r-1], q[r], a[i])) R--;while (L<r & ;& Jud (Q[l+1], q[l], a[i])) l++;q[++r]=a[i];} while (L<r && Jud (Q[r-1], q[r], q[l]) r--;while (l<r && Jud (q[l+1], q[l], Q[r])) L++;rep (i, L, R-1) {P2[i]=inter (Q[i], q[i+1]); if (p2[i].x>=p[1].x && p2[i].x<=p[m+1].x) p[++n]=p2[i];} Sort (p+1, p+1+n); int k1=1, k2=l; Ans=linf;rep (i, 1, n) {double x=p[i].x;while (k1<m && g[k1].b.x<x) k1++;while (k2<r && p2[k2].x& LT;X) K2++;line v; V.a.x=v.b.x=x, V.a.y=1, v.b.y=2;ans=min (ans, Inter (V, Q[k2]). Y-inter (V, g[K1]). y);} printf ("%.3lf\n", ans); return 0;}
BZOJ-1038 [ZJOI2008] Lookout tower