HDU3265--Posters
来源:互联网 发布:如何搜到淘宝卖家地址 编辑:程序博客网 时间:2024/05/22 02:44
Problem Description
Ted 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 ugly. 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, 50000). The edges of the window, the edges of the posters and the edges of the holes on the posters are all parallel with the coordinate axes.
However, Ted is such a picky guy that in every poster he finds something ugly. 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, 50000). The edges of the window, the edges of the posters and the edges of the holes on the posters are all parallel with the coordinate axes.
Input
The input contains several test cases. For each test case, 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.
The input ends with a line of single zero.
Output
For 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
/*思路:将举行切成4个矩形就可以*/#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define maxn 200008#define lson 2*id,l,mid#define rson 2*id+1,mid,rint X[2*maxn];int kx;struct ST{int l,r,len,add;}st[4*maxn];int binary_search(int a){int l=1,r=kx-1;while(l<r){int mid=(l+r)>>1;if(X[mid] >= a){r=mid;}else l=mid+1;}return l;}void buildtree(int id,int l,int r){st[id].l=l;st[id].r=r;if(l+1==r){st[id].add=st[id].len=0;return;}int mid=(l+r)>>1;buildtree(lson);buildtree(rson);st[id].add=st[id].len=0;}void PushUp(int id){if(st[id].add>=1)st[id].len=X[st[id].r]-X[st[id].l];else if(st[id].l+1==st[id].r) st[id].len=0;else st[id].len=st[2*id].len+st[2*id+1].len;}void update(int id,int l,int r,int ope){if(st[id].l==l && st[id].r==r){st[id].add+=ope;if(st[id].add >= 1) st[id].len=X[r]-X[l];else if(l+1 == r) st[id].len=0;else st[id].len=st[2*id].len + st[2*id+1].len;return;}if(st[2*id].r >= r){update(2*id,l,r,ope);PushUp(id);return;}if(st[2*id+1].l <= l){update(2*id+1,l,r,ope);PushUp(id);return;}update(2*id,l,st[2*id].r,ope);update(2*id+1,st[2*id+1].l,r,ope);PushUp(id);}struct Line{long long int x1,x2,y;bool vis;//标记是上边还是下边}line[2*maxn];bool cmp(Line a,Line b){return a.y<b.y;}int main(){int n;while(scanf("%d",&n)!=EOF&&n){int k=1;kx=1;for(int i=1;i<=n;i++){int x1,y1,x2,y2,x3,y3,x4,y4;scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);X[kx++]=x1;X[kx++]=x2;X[kx++]=x3;X[kx++]=x4;if(y1!=y3){line[k].x1=x1;line[k].x2=x2;line[k].y=y1;line[k++].vis=1;line[k].x1=x1;line[k].x2=x2;line[k].y=y3;line[k++].vis=0;}if(y4!=y2){line[k].x1=x1;line[k].x2=x2;line[k].y=y4;line[k++].vis=1;line[k].x1=x1;line[k].x2=x2;line[k].y=y2;line[k++].vis=0;}if(x1!=x3){line[k].x1=x1;line[k].x2=x3;line[k].y=y3;line[k++].vis=1;line[k].x1=x1;line[k].x2=x3;line[k].y=y4;line[k++].vis=0;}if(x2!=x4){line[k].x1=x4;line[k].x2=x2;line[k].y=y3;line[k++].vis=1;line[k].x1=x4;line[k].x2=x2;line[k].y=y4;line[k++].vis=0;}}//已经把所有的边都存好了。//接下来先离散下Xsort(X+1,X+kx);buildtree(1,1,kx-1);sort(line+1,line+k,cmp);//将这些线段按照高度排序long long int lx=0,ly=line[1].y;long long int ns=0;//用来存总覆盖面积for(int i=1;i<k;i++){if(line[i].vis){update(1,binary_search(line[i].x1),binary_search(line[i].x2),1);ns+=lx*(line[i].y-ly);lx=st[1].len;ly=line[i].y;}else {update(1,binary_search(line[i].x1),binary_search(line[i].x2),-1);ns+=lx*(line[i].y-ly);lx=st[1].len;ly=line[i].y;}}printf("%I64d\n",ns);}return 0;}
- HDU3265--Posters
- ZOJ3273 POJ3832 HDU3265 Posters
- 线段树 hdu3265 Posters
- hdu3265 Posters(切割+面积并)
- 扫描线 求挖空矩形合并面积 hdu3265 Posters
- hdu3265 Posters--扫描线 & 线段树(待解决)
- hdu3265-Posters 线段树+离散化 求矩形面积并
- HDU3265 Posters(线段树+扫描线——面积交)
- HDU3265 Posters(线段树,扫描线,矩形面积并)
- posters
- Posters
- hdu3265 矩形面积并
- 线段树面积并hdu3265
- HDU3265 线段树 线扫描
- hdu3265(好题翻译)
- hdu3265 Poster(扫描线)
- hdu3265(线段树求矩形面积并)
- HDU3265 Examining the Rooms【stirling数】
- Webview--如何让加载进来的页面自适应手机屏幕分辨率居中显示
- Intent的FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_REORDER_TO_FRONT
- 志与誓
- PowerISO v5.6
- centos6.4 bcm4313无线驱动安装
- HDU3265--Posters
- COMODO Firewall v6.1
- 第八周 项目一:任务二(友元函数完成运算符的重载)
- 北京联合大学CSDN高校俱乐部全体会议(2013.4.18)
- ORACLE distributed_lock_timeout参数
- 存储过程中select top 变量 和 if操作
- 第八周 项目一:任务三(扩展运算符功能)
- 黑马程序员——对基础的补充
- 为何与0xff进行与运算