HDU-3265-Posters
来源:互联网 发布:007支票打印软件 编辑:程序博客网 时间:2024/04/30 09:14
几乎是扫描线模板题,就是求矩形面积的并
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=5e4+1000;const int maxm=maxn*4;struct Node{ int l; int r; int len; int cover;}t[maxm];struct Line{ int x1; int x2; int y; int flag; Line(){} Line(int sx1,int sx2,int sy,int sflag) { x1=sx1; x2=sx2; y=sy; flag=sflag; } bool operator < (const Line &l)const { if(y==l.y) return x1<l.x1; return y<l.y; }}L[maxn*8];void Build(int l,int r,int index){ t[index].l=l; t[index].r=r; t[index].len=t[index].cover=0; if(l==r) return; int mid=(l+r)>>1; Build(l,mid,index<<1); Build(mid+1,r,index<<1|1);}void PushUp(int index){ if(t[index].cover>0) t[index].len=t[index].r-t[index].l+1; else if(t[index].l==t[index].r) t[index].len=0; else t[index].len=t[index<<1].len+t[index<<1|1].len;}void Update(int l,int r,int index,int val){ if(l>r) return; if(t[index].l==l&&t[index].r==r) { t[index].cover+=val; PushUp(index); return; } int mid=(t[index].l+t[index].r)>>1; if(r<=mid) Update(l,r,index<<1,val); else if(l>mid) Update(l,r,index<<1|1,val); else { Update(l,mid,index<<1,val); Update(mid+1,r,index<<1|1,val); } PushUp(index);}int n,cnt;int main(){ while(scanf("%d",&n)&&n) { cnt=0; Build(0,maxn,1); for(int i=0;i<n;i++) { int x1,x2,x3,x4,y1,y2,y3,y4; scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); L[cnt++]=Line(x1,x3,y1,1); L[cnt++]=Line(x1,x3,y2,-1); L[cnt++]=Line(x4,x2,y1,1); L[cnt++]=Line(x4,x2,y2,-1); L[cnt++]=Line(x3,x4,y1,1); L[cnt++]=Line(x3,x4,y3,-1); L[cnt++]=Line(x3,x4,y4,1); L[cnt++]=Line(x3,x4,y2,-1); } sort(L,L+cnt); long long ans=0; for(int i=0;i<cnt-1;i++) { Update(L[i].x1,L[i].x2-1,1,L[i].flag); ans+=(long long)t[1].len*(L[i+1].y-L[i].y); } printf("%I64d\n",ans); } return 0;}
0 0
- hdu 3265 Posters
- HDU 3265 - Posters
- hdu 3265 Posters
- HDU 3265 Posters
- HDU 3265 Posters
- HDU-3265-Posters
- HDU 3265 Posters
- HDU 3265 Posters
- hdu 3265 Posters
- zoj 3273 || hdu 3265 Posters
- hdu 3265 Posters(扫描线)
- hdu 3265 Posters(扫描线)
- hdu 3265 Posters 线段树+扫描线
- HDU 3265 Posters(线段树:扫描线)
- HDU 3265 Posters(线段树)
- HDU 3265 Posters (线段树-扫描线)
- HDU 3265 Posters (线段树+扫描线+矩形分割)
- HDU 3265 Posters(面积并模板题)
- Raphael之arrow-end属性简析
- 别把我对你的爱转发给无关的看客,我不想将爱漫天广播
- 嵌入式杂项
- css框架960gridSystem和1200的
- VB.NET版机房收费系统---报表
- HDU-3265-Posters
- ACdream 1121 喵喵的IDE
- 编码的世界
- file_put_contents
- leetcode: Jump Game
- Android Notification通知详解
- 大数阶乘
- 《白帽子讲web安全》笔记之认证与授权那些事
- Binary Tree Zigzag Level Order Traversal