The main effect and simulated annealing problem: see http://blog.csdn.net/popoqqq/article/details/39340759
This time with a half plane to write again ... After the half plane intersection is obtained, enumerate each point of the original and half plane intersection to find the answer
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <
Algorithm> #define M 310 #define EPS 1e-7 using namespace std; struct point{double x,y;}
POINTS[M];
struct line{point *p1,*p2;
Double k,b;
void Get_parameters () {k= (double) (p1->y-p2->y)/(P1->X-P2->X);
b=p1->y-k*p1->x;
BOOL operator < (const line &x) Const {if (Fabs (K-X.K) <eps) return B < x.b;
return k < X.K;
}}lines[m];
int n;
Double Ans=1e11;
Line *stack[m];int top;
Inline point get_intersection (the const line &l1,const line &L2) {point re;
re.x=-(l1.b-l2.b)/(L1.K-L2.K);
re.y=l1.k*re.x+l1.b;
return re; } void Insert (line &l) {while (top>=2) {if get_intersection (*stack[top],l). x < Get_intersection (*stack[top
-1],*stack[top]). x)--top;
else break;
} stack[++top]=&l;
Double F (double x) {int i;
Double re=0;
for (i=1;i<=top;i++) Re=max (re,stack[i]->k*x+stack[i]->b);return re;
Double G (double x) {int i;
for (i=n;i;i--) if (x>=points[i].x) break;
Return points[i].y+ (x-points[i].x)/(points[i+1].x-points[i].x) * (POINTS[I+1].Y-POINTS[I].Y);
int main () {int i;
cin>>n;
for (i=1;i<=n;i++) scanf ("%lf", &points[i].x);
for (i=1;i<=n;i++) scanf ("%lf", &points[i].y); for (i=1;i<n;i++) lines[i].p1=points+i,lines[i].p2=points+i+1,lines[i].
Get_parameters ();
Sort (lines+1,lines+n); for (i=1;i<n;i++) if (i==n-1| |
Fabs (LINES[I].K-LINES[I+1].K) >eps) Insert (lines[i));
for (i=1;i<=n;i++) ans=min (ans,f (points[i].x)-points[i].y);
for (i=1;i<top;i++) {point p=get_intersection (*stack[i],*stack[i+1]);
Ans=min (Ans,p.y-g (p.x));
printf ("%.3lf\n", ans);
}