The main effect of the topic:
To two convex polygons, to find the area of intersection.
Topic Analysis:
Ask for a half plane turn.
The code is as follows:
#include <cstdio> #include <algorithm> #include <cmath> using namespace std;
struct point{double x,y; Point () {} point (double x,double y): x (x), Y (y) {} point operator + (const point &c) const {return point (x+c.x,y+ C.Y);
Point operator-(const point &c) const {return point (X-C.X,Y-C.Y);}
Double operator * (const point &c) const {return x*c.y-y*c.x;} Point operator * (const double &c) const {return point (X*c,y*c);}}
B[1000];
struct line{point p,v;
Double Alpha;
BOOL operator < (const line &C) const{return alpha<c.alpha;}
Line () {} line (point A,point B):p (a), V (b-a) {alpha=atan2 (v.y,v.x);}
Point operator ^ (const line &c) const {point tmp=p-c.p;
Double rate= (c.v*tmp)/(V*C.V);
return p+v*rate;
}}a[1000000],p[1000000];
int tot,m,n,l,r;
BOOL Onleft (Point p,line L) {point tmp=p-l.p;
Return l.v*tmp>=0;
} void Half_plane_intersection () { Sort (a+1,a+1+tot);
for (int i=1;i<=tot;i++) {while (r-l>=2 &&!onleft (p[r-1]^p[r-2],a[i)) r--;
if (r-l>=1 && fabs (P[R-1].V*A[I].V) <=0) P[r-1]=onleft (A[i].p,p[r-1]) a[i]:p [r-1];
else P[r++]=a[i];
for (;;)
{if (r-l>=2 &&!onleft (p[r-1]^p[r-2],p[l)) r--;
else if (r-l>=2 &&!onleft (p[l]^p[l+1],p[r-1)) l++;
else break;
int main () {scanf ("%d", &m);
tot=0;
for (int j=1;j<=m;j++) {scanf ("%d", &n);
for (int i=1;i<=n;i++) {scanf ("%lf%lf", &b[i].x,&b[i].y);
if (i!=1) A[++tot]=line (B[i-1],b[i]);
} a[++tot]=line (b[n],b[1]);
} half_plane_intersection ();
if (r-l<=2) printf ("0.000\n");
else {int sum=0;
for (int i=l+1;i<r;i++) b[++sum]=p[i-1]^p[i];
B[++SUM]=P[R-1]^P[L];
Double ans=0; for (int i=2;i<=sum;i++) Ans+=b[i-1]*b[i];
ANS+=B[SUM]*B[1];
printf ("%.3lf\n", ans/2.0);
return 0; }