"Half-Plane" bzoj1038 [ZJOI2008] Lookout tower

Source: Internet
Author: User

http://m.blog.csdn.net/blog/qpswwww/44105605

#include <cstdio> #include <cmath> #include <algorithm>using namespace std; #define EPS 0.0000001# Define N 311typedef Double db;const db Pi=acos ( -1.0); struct point{db x, y;}; typedef point Vector; Vector operator-(const point &a,const point &b) {return (Vector) {a.x-b.x,a.y-b.y};} Vector operator * (const vector &AMP;A,CONST db &k) {return (Vector) {a.x*k,a.y*k};} Vector operator + (const vector &a,const vector &b) {return (vector) {a.x+b.x,a.y+b.y};} DB Cross (Vector A,vector b) {return a.x*b.y-a.y*b.x;} struct line{point P; Vector v;    DB ang;        Line () {} line (const point &a,const point &b) {v=b-a;        P=a;        Ang=atan2 (v.y,v.x);       if (ang<0) Ang+=2.0*pi; }};bool operator < (const line &a,const line &b) {return a.ang<b.ang;} BOOL Onleft (line L,point a) {return cross (L.V,A-L.P) >0; Point Getjiaodian (line A,line b) {return a.p+a.v* (Cross (B.V,A.P-B.P)/cross (A.V,B.V)); int n; Point Ps[n]; Line Q[n];int Head=1,tail= 1;    Line Ls[n];void BPMJ () {sort (ls+1,ls+n+1);    Q[1]=LS[1]; for (int i=2;i<=n;++i) {while (head<tail&& (!        Onleft (Ls[i],ps[tail-1]))--tail; while (head<tail&& (!        Onleft (Ls[i],ps[head])) ++head;        Q[++tail]=ls[i];            if (Fabs (Q[TAIL].V,Q[TAIL-1].V)) <eps) {--tail;          if (Onleft (Q[TAIL],LS[I].P)) q[tail]=ls[i];      } if (Head<tail) Ps[tail-1]=getjiaodian (Q[tail-1],q[tail]); } while (head<tail&& (!    Onleft (Q[head],ps[tail-1]))--tail; Ps[tail]=getjiaodian (Q[tail],q[head]);} int nn;    Point A[n];d b ans=999999999999999999.0; #define INF 10000000000.0int Main () {//Freopen ("Bzoj1038.in", "R", stdin);    scanf ("%d", &nn);    for (int i=1;i<=nn;++i) scanf ("%lf", &a[i].x);    for (int i=1;i<=nn;++i) scanf ("%lf", &a[i].y);    for (int i=1;i<nn;++i) ls[++n]=line (a[i],a[i+1]);    Ls[++n]=line (point) {Inf,inf}, (point) {-inf,inf}); Ls[++n]=line ((Point) {-inf,inf}, (point) {-inf,-inf});    Ls[++n]=line (point) {-inf,-inf}, (point) {inf,-inf});    Ls[++n]=line (point) {Inf,-inf}, (point) {inf,inf});    BPMJ ();          for (int i=head;i<=tail;++i) for (int j=1;j<nn;++j) if (ps[i].x>=a[j].x&&ps[i].x<=a[j+1].x)            {db ty=a[j].y+ (ps[i].x-a[j].x)/(a[j+1].x-a[j].x) * (A[J+1].Y-A[J].Y);            Ans=min (Ans,ps[i].y-ty);          Break } for (int i=1;i<=nn;++i) {for (int j=head;j<tail;++j) if (a[i].x>=ps[j].x&&a[i].x&              lt;=ps[j+1].x) {db ty=ps[j].y+ (a[i].x-ps[j].x)/(ps[j+1].x-ps[j].x) * (PS[J+1].Y-PS[J].Y);            Ans=min (ANS,TY-A[I].Y); } if (a[i].x>=ps[tail].x&&a[i].x<=ps[head].x) {db ty=ps[tail].y+ (A[i].x-ps[tail].            x)/(ps[head].x-ps[tail].x) * (PS[HEAD].Y-PS[TAIL].Y);          Ans=min (ANS,TY-A[I].Y);    }} printf ("%.3lf\n", ans); return 0;}

Half-plane bzoj1038 [ZJOI2008] Lookout tower

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.