Posters
Time Limit: 5000/2000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2312 accepted submission (s): 515
Problem descriptionted has a new house with a huge window. in this big summer, Ted decides to decorate the window with some posters to prevent the glare outside. all things that Ted can find are rectangle posters.
However, Ted is such a picky guy that in every poster he finds something uugly. so before he pastes a poster on the window, he cuts a rectangular hole on that poster to remove the ugly part. ted is also a careless guy so that some of the pasted posters may overlap
When He pastes them on the window.
Ted wants to know the total area of the window covered by posters. Now it is your job to figure it out.
To make your job easier, we assume that the window is a rectangle located in a rectangular coordinate system. the window's bottom-left corner is at position (0, 0) and top-right corner is at position (50000,500 00 ). the edges of the window, the edges of
Posters and the edges of the holes on the posters are all parallel with the coordinate axes.
Inputthe input contains several test cases. for each test cases, the first line contains a single integer N (0 <n <= 50000), representing the total number of posters. each of the following n lines contains 8 integers X1, Y1, X2, Y2, X3, Y3, X4, Y4, showing details about
One poster. (x1, Y1) is the coordinates of the poster's bottom-left corner, and (X2, Y2) is the coordinates of the poster's top-right corner. (X3, Y3) is the coordinates of the hole's bottom-left corner, while (X4, Y4) is the coordinates of the hole's top-Right
Corner. it is guaranteed that 0 <= xi, Yi <= 50000 (I = 1... 4) and X1 <= X3 <X4 <= x2, Y1 <= Y3 <Y4 <= y2.
The input ends with a line of single zero.
Outputfor each test case, output a single line with the total area of window covered by posters.
Sample Input
20 0 10 10 1 1 9 92 2 8 8 3 3 7 70
Sample output
56
Source2009 Asia Ningbo regional contest hosted by nit
Recommendlcy
Question: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3265
It's a post, and this time we cut off a rectangle in the rectangle and asked about the area of the last graph...
Analysis: simply think of each rectangle as four rectangles. The other is to calculate the sum of the rectangle area...
This question may show the rectangle that was just cut off on the boundary. You have to judge it, or you just need to re it. I actually re it early in the morning... Recently, why are we always encountering re-engineering and hangdian's _ int64? I forgot.
Code:
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#define ls rt<<1#define rs rt<<1|1#define lson l,m,ls#define rson m,r,rsusing namespace std;const int mm=222222;const int mn=mm<<2;struct seg{ int x,y1,y2,c;}g[mn];int L,R,val,len[mn],t[mn],y[mm];void build(){ memset(len,0,sizeof(len)); memset(t,0,sizeof(t));}void updata(int l,int r,int rt){ if(L<=y[l]&&R>=y[r])t[rt]+=val; else { int m=(l+r)>>1; if(L<y[m])updata(lson); if(R>y[m])updata(rson); } if(t[rt])len[rt]=y[r]-y[l]; else if(l>=r)len[rt]=0; else len[rt]=len[ls]+len[rs];}bool cmp(seg a,seg b){ return a.x<b.x;}int main(){ int i,n,m,x1,y1,x2,y2,x3,y3,x4,y4; __int64 ans; while(scanf("%d",&n),n) { for(i=0;i<n;++i) { scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); y[i]=y1,y[i+n]=y2,y[i+n*2]=y3,y[i+n*3]=y4; g[i].x=x1,g[i].y1=y1,g[i].y2=y2,g[i].c=1; g[i+n].x=x3,g[i+n].y1=y1,g[i+n].y2=y2,g[i+n].c=-1; g[i+n*2].x=x3,g[i+n*2].y1=y1,g[i+n*2].y2=y3,g[i+n*2].c=1; g[i+n*3].x=x4,g[i+n*3].y1=y1,g[i+n*3].y2=y3,g[i+n*3].c=-1; g[i+n*4].x=x3,g[i+n*4].y1=y4,g[i+n*4].y2=y2,g[i+n*4].c=1; g[i+n*5].x=x4,g[i+n*5].y1=y4,g[i+n*5].y2=y2,g[i+n*5].c=-1; g[i+n*6].x=x4,g[i+n*6].y1=y1,g[i+n*6].y2=y2,g[i+n*6].c=1; g[i+n*7].x=x2,g[i+n*7].y1=y1,g[i+n*7].y2=y2,g[i+n*7].c=-1; } sort(y,y+n*4); sort(g,g+n*8,cmp); for(m=i=0;i<n*4;++i) if(y[m]!=y[i])y[++m]=y[i]; build(); for(ans=i=0;i<n*8;++i) { L=g[i].y1,R=g[i].y2,val=g[i].c; if(L<R)updata(0,m,1); if(g[i].x<g[i+1].x)ans+=(__int64)(g[i+1].x-g[i].x)*(__int64)len[1]; } printf("%I64d\n",ans); } return 0;}