Topic Description
Transfer Door solving
First, the bottom line is made with a half plane, and then a convex shell is formed.
Then the answer must be at the turning point at the bottom or at the point on the convex shell.
Because... The extremum of piecewise function must be at the segment point.
Then the violence, the enumeration, the intersection ...
But the key is the accuracy of this problem ah ... My Code precision is <=1e-9, the initial range of the half plane intersection must be 1e10 or 1e11 before ... Code
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <
Cmath> using namespace std;
#define N 505 Const double eps=1e-9;
const double INF=1E10;
int dcmp (double x) {if (x<=eps&&x>=-eps) return 0;
Return (x>0) 1:-1;
struct Vector {double x,y;
Vector (double x=0,double y=0) {x=x,y=y; BOOL operator < (const Vector &a) const {return x<a.x| |
(X==A.X&&Y<A.Y);
}
};
typedef Vector Point;
Vector operator + (vector a,vector b) {return vector (A.X+B.X,A.Y+B.Y);}
Vector operator-(vector a,vector b) {return vector (A.X-B.X,A.Y-B.Y);}
Vector operator * (vector a,double b) {return vector (a.x*b,a.y*b);}
int n,cnt,ncnt;
Double ans;
Point P[n],poly[n],npoly[n]; Double Dot (vector a,vector b) {return A.X*B.X+A.Y*B.Y.} double Cross (vector a,vector b) {return a.x*b.y-a.y*b.x
; Double Len (Vector a) {return sqrt (Dot (a,a));} bool Insls (poinT a,point b,point c,point D) {int x=dcmp (Cross (c-b,a-b));
int y=dcmp (Cross (d-b,a-b));
Return x&&y&&x!=y;
Point GLI (Point p,vector v,point q,vector w) {Vector u=p-q;
Double T=cross (w,u)/cross (V,W);
return p+v*t;
} void Init () {cnt=0;
Poly[++cnt]=point (Inf,inf);
Poly[++cnt]=point (-inf,inf);
Poly[++cnt]=point (-inf,-inf);
Poly[++cnt]=point (Inf,-inf);
} void halfp (Point a,point B) {point c,d;
ncnt=0;
for (int i=1;i<=cnt;++i) {c=poly[i%cnt+1];
d=poly[(i+1)%cnt+1];
if (dcmp (Cross (c-b,a-b)) >=0) Npoly[++ncnt]=c;
if (Insls (a,b,c,d)) Npoly[++ncnt]=gli (A,B-A,C,D-C);
} cnt=ncnt;
for (int i=1;i<=cnt;++i) poly[i]=npoly[i];
int main () {scanf ("%d", &n);
if (n==1) {puts ("0.000"); return 0;}
for (int i=1;i<=n;++i) scanf ("%lf", &p[i].x);
for (int i=1;i<=n;++i) scanf ("%lf", &p[i].y);
Init (); for (int i=1;i&lT;n;++i) HALFP (p[i],p[i+1]);
Ans=1e60; for (int i=1;i<=n;++i) for (int j=1;j<=cnt;++j) if (dcmp (poly[j%cnt+1].x-p[i].x) <=0&& DCMP (poly[(j+1)%cnt+1].x-p[i].x) >=0) {Point P=gli (poly[j%cnt+1],poly[(j+1)%cnt+1]-poly[j%c
Nt+1],p[i],vector (0,inf));
Ans=min (Ans,len (p-p[i)); for (int i=1;i<=cnt;++i) for (int j=1;j<=n;++j) if (dcmp (p[j%n+1].x-poly[i].x) <=0&& AMP;DCMP (p[(j+1)%n+1].x-poly[i].x) >=0) {Point P=gli (p[j%n+1],p[(j+1)%n+1]-p[j%n+1],poly[i]
, Vector (0,-inf));
Ans=min (Ans,len (p-poly[i));
printf ("%.3lf\n", ans); }