Topic Description Analysis:
The topic said "can see" means in the line of each segment of the line toward the x-axis positive direction, the left part of the line (in fact, is the line of each segment of the line above)
So what we are asking for is that the polyline is a straight line intersecting a bottom facing convex shell (similar to the appearance of the two function a>0), on the Internet that this is to seek a half plane , here is not so tall, direct ask. Solution: First, the lines is sorted according to the slope size, and a stack is used to maintain the straight line that forms the convex hull.
if the intersection of the current line and stack [Top-2] (the penultimate element of the stack) is less than the intersection of Stack [top-1] and Stack [top-2], then stack [top-1] This element out of the team (The basis is that the current line is better than the first straight line to the penultimate line, not the penultimate one) Note that if you have a straight line with a slope equal to the maximum of the y-axis intercept, you cannot count the intersection. because the distance between the two lines is calculated, the distance can be expressed as piecewise function, and each function is the form of a function, then the distance should also be the form of a function (or an ordinary function), the extreme value is at the intersection point of the line (fold points) to take.
It is divided into two parts.
Part 1: Convex shell The corresponding distance of the folding point Part 2: the distance corresponding to the fold point of the polyline given by the topic.
#include <cstdio> #include <cmath> #include <algorithm> using namespace std;
#define MAXN Double eps=1e-12;
const double INF=1E20; struct point{int x,y;}
A[MAXN+10]; struct line{double k,b;}
L[MAXN+10],STAK[MAXN+10];
int n,top;
Double ans=inf,cro[maxn+10];
Double GETK (point A,point b) {return 1.0* (A.Y-B.Y)/(a.x-b.x);} void Read () {scanf ("%d", &n);
for (int i=1;i<=n;i++) scanf ("%d", &a[i].x);
for (int i=1;i<=n;i++) scanf ("%d", &a[i].y);
for (int i=1;i<n;i++) {L[I].K=GETK (a[i],a[i+1]);
L[I].B=1.0*A[I].Y-1.0*A[I].X*L[I].K;
BOOL CMP (line A,line b) {if fabs (A.K-B.K) <eps) return a.b<b.b;
Return a.k<b.k; Double Getcrossp (line A,line b) {//get Crossover point return (a.b-b.b)/(B.K-A.K);} void Getconvex () {sort (l+1
, l+n,cmp);
STAK[TOP++]=L[1];
for (int i=2;i<n;i++) {while (top) {if (Fabs (STAK[TOP-1].K-L[I].K) <eps) top--; else if (TOP>1&&GETCROSSP (L[i],stak[top-2]) <=GETCROSSP (stak[top-2],stak[top-1)) to
p--;
else break;
} Stak[top++]=l[i];
Double Gety (line a,double x0) {return a.k*x0+a.b;} void Getans () {//part 1 for (int i=1;i<top;i++) {
Double X0=getcrossp (stak[i-1],stak[i]);
cro[i]=x0;
int k=-1;
for (int j=1;j<n;j++) if (x0<=1.0*a[j+1].x) {k=j;
Break
} if (k==-1) continue;
Line T;
T.K=GETK (a[k],a[k+1]);
T.B=1.0*A[K].Y-1.0*A[K].X*T.K;
Double Tmp=gety (stak[i],x0)-gety (t,x0);
if (tmp>=0.0) ans=min (ans,tmp);
}//part 2 for (int i=1;i<=n;i++) {int k=-1;
for (int j=1;j<top;j++) if (1.0*a[i].x<=cro[j]) {k=j-1;
Break
} if (k==-1) continue; Double TMP=gety (stak[k],1.0*a[i].x) -1.0*a[i].y;
if (tmp>=0.0) ans=min (ans,tmp);
printf ("%.3lf\n", ans);
int main () {read ();
Getconvex ();
Getans ();
return 0; }