http://acm.hust.edu.cn/vjudge/problem/10769
For the n Zhang Hai, cut a rectangle on each poster to find out the area and
The cut-off poster is divided into four rectangles, which is the common area and problem.
#include <iostream>#include<string>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<algorithm>#include<stack>#include<queue>#include<cctype>#include<vector>#include<iterator>#include<Set>#include<map>#include<sstream>using namespacestd;#defineMem (A, B) memset (A,b,sizeof (a))#definePF printf#defineSF scanf#defineSPF sprintf#definePB Push_back#defineDebug printf ("!\n")#defineMAXN 50000+5#defineMAX (A, b) a>b?a:b#defineBlank pf ("\ n")#defineLL Long Long#defineAll (x) X.begin (), X.end ()#defineINS (x) Inserter (X,x.begin ())#definePqueue priority_queue#defineINF 0x3f3f3f3f#defineLS (rt<<1)#defineRS (rt<<1|1)intn,m;inthh[maxn],col[maxn<<3],len[maxn<<3];structnode{intL,r,x,c; Node () {} node (intAintBintCintd): L (a), R (b), X (c), C (d) {}BOOL operator< (ConstNode &b)Const { returnx<b.x; }}A[MAXN<<3];voidPushup (intRtintLintR) { if(Col[rt]) {LEN[RT]= hh[r+1] -Hh[l]; } Else if(l==r) Len[rt] =0; Else{Len[rt]= len[ls]+Len[rs]; }}voidUpdateintValintLintRintLintRintRT) { if(L<=l && r<=R) {Col[rt]+=Val; Pushup (RT,L,R); return; } intMid = (l+r) >>1; if(L <=mid) Update (VAL,L,R,L,MID,LS); if(R > Mid) Update (val,l,r,mid+1, R,rs); Pushup (rt,l,r);}intMain () {intI,j,k,t,kase=1; while(~SF ("%d", &n) &&N) {intv=0; LL sum=0; for(i=0; i<n;i++) { intX1,y1,x2,y2; intX1,y1,x2,y2; SF ("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x1,&y1,&x2,&Y2); if(x1!=X1) {Hh[v]=Y1; A[v+ +] = node (y1,y2,x1,1); HH[V]=Y2; A[v+ +] = node (y1,y2,x1,-1); } if(x2!=y2) {Hh[v]=Y1; A[v+ +] = node (y1,y2,x2,1); HH[V]=Y2; A[v+ +] = node (y1,y2,x2,-1); } if(y1!=Y1) {Hh[v]=Y1; A[v+ +] = node (y1,y1,x1,1); HH[V]=Y1; A[v+ +] = node (y1,y1,x2,-1); } if(y2!=Y2) {Hh[v]=Y2; A[v+ +] = node (y2,y2,x1,1); HH[V]=Y2; A[v+ +] = node (y2,y2,x2,-1); }} sort (Hh,hh+v); Sort (A,a+v); intD =1; for(i=1; i<v;i++) { if(hh[i]!=hh[i-1]) hh[d++] =Hh[i]; } mem (len,0); Mem (col,0); for(i=0; i<v-1; i++) { intL = Lower_bound (HH,HH+D,A[I].L)-hh; intR = Lower_bound (HH,HH+D,A[I].R)-hh-1; Update (A[I].C,L,R,0, d1,1); Sum+=len[1]*((Long Long) a[i+1].x-a[i].x); //PF ("%lf%lf\n", sum,len[1]);} pf ("%i64d\n", sum); } return 0;}
Hdu 3265 Rectangular shear area and