hdu 4419 Colourful Rectangle 杭州赛区 1010 (解题报告)
来源:互联网 发布:网络教育深圳招生 编辑:程序博客网 时间:2024/06/05 19:38
杭州赛区最后一题。。。。
最近看线段树还是有收获的·~~~
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#define ls rt<<1#define rs rt<<1|1#define lson l,m,ls#define rson m+1,r,rs#define sf scanf #define pf printfusing namespace std;const int N = 10000 * 2 +10;//437MS 2512K 3151 B C++ /* 比赛的时候也想到了容斥原理,但是并没有那么做,而是用cnt[3][rt]记录每种颜色的线 条有还是没有,结果把自己卡死了。。。。 比赛后用容斥原理做了一下,好吧,还是容斥原理好做些。 建立7课线段树,拿矩形覆盖面积模版一套即可求出 R, G, B, RG, RB, GB, RGB 7种颜色 的面积值sum[],但这个并不是最终答案,画个韦恩图就得出关系了,进而求得are[]。 注意:sum,are要 __int64 */ int cnt[N<<2];int len[N<<2];int tot[10];__int64 sum[10],are[10];struct segment{int lx,rx,y;int kind;}s[10][N]; int x[10][N];int xcount[10];bool cmp(segment s1,segment s2){return s1.y<s2.y;}void pushup(int l,int r,int rt,int k){if(cnt[rt])len[rt]=x[k][r+1]-x[k][l];else if(l==r)len[rt]=0;else len[rt]=len[ls]+len[rs];}void updata(int ql,int qr,int l,int r,int rt,int kind,int k){ int m=(r+l)>>1;if(l==ql && r==qr) cnt[rt]+=kind; else if(qr<=m) updata(ql,qr,lson,kind,k);else if(ql>m) updata(ql,qr,rson,kind,k);else{ updata(ql,m,lson,kind,k); updata(m+1,qr,rson,kind,k); }pushup(l,r,rt,k);}void input(int a,int x1,int x2,int y1,int y2){ x[a][tot[a]]=x1; s[a][tot[a]].lx=x1; s[a][tot[a]].rx=x2; s[a][tot[a]].y=y1; s[a][tot[a]].kind=1; tot[a]++; x[a][tot[a]]=x2; s[a][tot[a]].lx=x1; s[a][tot[a]].rx=x2; s[a][tot[a]].y=y2; s[a][tot[a]].kind=-1; tot[a]++;} #define test(a,b) for(int ii=0;ii<(b);ii++)printf("%d%c",(a)[ii],ii==(b)-1?'\n':' ') #define cntd(a,b) unique((a),(a)+(b))-(a) #define lb(a,b,c) lower_bound((a),(a)+(b),(c))-(a) #define fill(a) memset( (a),0,sizeof((a)) ); int main(){int n,tt,col,cas=1;scanf("%d",&tt);while(tt--){ scanf("%d",&n);fill(tot); fill(sum);fill(are);for(int i=0;i<n;i++){ getchar(); char c; int x1,y1,x2,y2;scanf("%c%d%d%d%d",&c,&x1,&y1,&x2,&y2);if(c=='R') { input(0,x1,x2,y1,y2); input(3,x1,x2,y1,y2); input(4,x1,x2,y1,y2); input(6,x1,x2,y1,y2); }if(c=='G') { input(1,x1,x2,y1,y2); input(3,x1,x2,y1,y2); input(5,x1,x2,y1,y2); input(6,x1,x2,y1,y2); } if(c=='B') { input(2,x1,x2,y1,y2); input(4,x1,x2,y1,y2); input(5,x1,x2,y1,y2); input(6,x1,x2,y1,y2); } } //test(tot,7); for(int i=0;i<7;i++){ sort(x[i],x[i]+tot[i]); sort(s[i],s[i]+tot[i],cmp); xcount[i]=cntd(x[i],tot[i])-1; fill(cnt); fill(len); for(int j=0;j<tot[i]-1;j++){ int fx1=lb(x[i],xcount[i],s[i][j].lx); int fx2=lb(x[i],xcount[i],s[i][j].rx)-1; //printf("%d %d %d\n",i,fx1,fx2); updata(fx1,fx2,0,xcount[i]-1,1,s[i][j].kind,i); sum[i]+=(__int64)(s[i][j+1].y-s[i][j].y)*len[1]; } } are[0]=sum[6]-sum[5]; are[1]=sum[6]-sum[4]; are[2]=sum[6]-sum[3]; are[3]=sum[4]-sum[2]-are[0]; are[4]=sum[5]-sum[1]-are[2]; are[5]=sum[3]-sum[0]-are[1]; are[6]=sum[0]-are[0]-are[3]-are[4]; printf("Case %d:\n",cas++);for(int i=0;i<7;i++) printf("%I64d\n",are[i]); }return 0;}
- hdu 4419 Colourful Rectangle 杭州赛区 1010 (解题报告)
- hdu 4419 Colourful Rectangle (2012杭州区域赛 1010 )
- HDU 4419 Colourful Rectangle
- hdu 4419 Colourful Rectangle
- HDU 4419 Colourful Rectangle(12年杭州 线段树+离散化+扫描线)
- HDU 4419 Colourful Rectangle(12年杭州 线段树+离散化+扫描线)
- hdu 4419 Colourful Rectangle(扫描线)
- hdu 4419 Colourful Rectangle(矩形面积并)
- hdu - 4419 - Colourful Rectangle - 线段树
- HDU-4419-Colourful Rectangle(线段树)
- HDU 4419 Colourful Rectangle 扫描线
- Hdu 4419 Colourful Rectangle(矩形颜色交)
- HDU 4495 Rectangle 解题报告
- hdu-4419-Colourful Rectangle-线段树求面积并
- Hdu 4419 Colourful Rectangle(线段树扫描线)
- HDU 4419 Colourful Rectangle (线段树扫描线)
- HDU 4419 Colourful Rectangle --离散化+线段树扫描线
- hdu 4409 Family Name List 金华赛区1010 (解题报告)
- .net密码找回
- param中的路径
- Process and Thread引发的几个问题
- 嵌入式项目介绍
- android---Intent的使用
- hdu 4419 Colourful Rectangle 杭州赛区 1010 (解题报告)
- 真正花时间静心做自己的事情
- asp.net 实现无限级分类
- MYCP cgcBase随手记
- 新手教程:107条Javascript的常用语句
- JAVA 抽象类运用
- Linux文件系统的一些理解
- 揭开linux内核中container_of的神秘面纱
- html