#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 &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