Topic: given n convex polygons, the area of intersection is obtained.
After many years I finally put the complete half-plane to make out ... It's so hard ...
Once wrote a re to die so put on hold 0.0 today write a pitch is WA to the rhythm of death ...
Not much to say directly on the code in fact Rujia classmates write trouble every time after inserting a half plane without both ends of the deletion of only one end of the final processing of the end of the part on the line
300 Souvenir ... It's good to cut a template question.
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define M 510#define EPS 1e-7using namespace std;struct point{double x,y;point () {}point (double _,double __) : X (_), Y (__) {}point operator + (const point &p) Const{return Point (X+P.X,Y+P.Y);} Point operator-(const point &p) Const{return Point (X-P.X,Y-P.Y); Double operator * (const point &p) Const{return x*p.y-y*p.x;} Point operator * (const double &rate) Const{return point (x*rate,y*rate); void Read () {scanf ("%lf%lf", &x,&y);}} Points[m];struct line{point p,v;double alpha;line () {}line (const point &p1,const point &p2):p (p1), V (P2-P1) { Alpha=atan2 (v.y,v.x);} BOOL operator < (const line &L) Const{return Alpha < L.alpha;}} Lines[m];int n,m,tot;line *q[m];int r,h;double ans;bool onleft (const point &p,const line &l) {return (l.p-p) *l.v& gt;=0;} Point Get_intersection (const line &l1,const line &l2) {point u=l1.p-l2.p;double temp= (L2.V*u)/(L1.V*L2.V); return l1.p+l1.v*temp;} void Get_half_plane_intersection () {int i;for (i=1;i<=tot;i++) {while (r-h>=2 &&!) Onleft (Get_intersection (*q[r],*q[r-1]), Lines[i]) q[r--]=0x0;if (r-h>=1 && fabs (lines[i].v*q[r]->v) <=0) Q[r]=onleft (Lines[i].p,*q[r])? &lines[i]:q[r];else q[++r]=&lines[i];} while (r-h>=2 &&!) Onleft (Get_intersection (*q[h+1],*q[h+2]), *q[r]) q[++h]=0x0;while (r-h>=2 &&!) Onleft (Get_intersection (*q[r],*q[r-1]), *q[h+1])) q[r--]=0x0;} int main () {int i,j;cin>>n;for (i=1;i<=n;i++) {point first,p1,p2;scanf ("%d", &m); Read ();p 2=first;for (j=2;j<=m;j++) {p1=p2;p2. Read (); Lines[++tot]=line (P1,P2);} Lines[++tot]=line (P2,first);} Sort (lines+1,lines+tot+1); Get_half_plane_intersection (); if (r-h<=2) return puts ("0.000"), 0;tot=0;for (i=h+2;i<=r;i++) points[++tot]=get _intersection (*q[i],*q[i-1]);p oints[++tot]=get_intersection (*q[r],*q[h+1]); for (i=2;i<=tot;i++) ans+=points[ I-1]*POINTS[I];ANS+=POINTS[TOT]*POINTS[1];p rintf ("%.3lf\n", ANS/2); return 0;}
Bzoj 2618 CQOI2006 convex polygon semi-plane intersection