"Half-plane intersection" bzoj2618 [Cqoi2006] Convex polygon

Source: Internet
Author: User

#include <cstdio> #include <cmath> #include <algorithm>using namespace std; #define EPS 0.0000001# Define N 511typedef 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,mm;    Point tmp[51];d b area;int Main () {scanf ("%d", &nn);        for (int i=1;i<=nn;++i) {scanf ("%d", &mm);        for (int j=1;j<=mm;++j) scanf ("%lf%lf", &tmp[j].x,&tmp[j].y);        for (int j=1;j<mm;++j) ls[++n]=line (tmp[j],tmp[j+1]);      Ls[++n]=line (tmp[mm],tmp[1]);    } BPMJ (); for (int i=head+1;i<tail;++i) Area+=cross(Ps[i]-ps[head],ps[i+1]-ps[head]);    printf ("%.3lf\n", area/2.0); return 0;}

Half plane intersection bzoj2618 [Cqoi2006] convex polygon

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.