ZOJ 1610 线段树区间染色
来源:互联网 发布:数据处理作图软件 编辑:程序博客网 时间:2024/05/18 12:39
给长度8000米的板,对其中区间染色,问最后能看到的颜色,和该颜色一共出现了几段
线段覆盖法
数据比较水 也可以暴力水过
线段树:
#include "stdio.h"#include "string.h"struct node{ int l,r,c;}data[40010];int color[8011];void build(int l,int r,int k){ int mid; data[k].l=l; data[k].r=r; data[k].c=-1; if (l==r) return ; mid=(l+r)/2; build(l,mid,k*2); build(mid+1,r,k*2+1);}void updata(int l,int r,int k,int op){ int mid; if (data[k].c==op) return ; if (data[k].l==l && data[k].r==r) { data[k].c=op; return ; } if (data[k].c!=-1) { data[k*2].c=data[k*2+1].c=data[k].c; data[k].c=-1; } mid=(data[k].l+data[k].r)/2; if (r<=mid) updata(l,r,k*2,op); else if (l>mid) updata(l,r,k*2+1,op); else { updata(l,mid,k*2,op); updata(mid+1,r,k*2+1,op); } if (data[k*2].c==data[k*2+1].c) data[k].c=data[k*2].c; else data[k].c=-1;}void query(int k){ if (data[k].l==data[k].r) { color[data[k].l]=data[k].c; return ; } if (data[k].c!=-1) data[k*2].c=data[k*2+1].c=data[k].c; query(k*2); query(k*2+1);}int main(){ int n,l,r,c,m,now,i; int sum[8011]; m=8010; while (scanf("%d",&n)!=EOF) { build(0,m,1); while (n--) { scanf("%d%d%d",&l,&r,&c); r--; updata(l,r,1,c); } memset(color,-1,sizeof(color)); query(1); memset(sum,0,sizeof(sum)); now=color[0]; sum[now]++; for (i=1;i<=m;i++) if (color[i]!=now) { now=color[i]; sum[now]++; } for (i=0;i<=m;i++) if (sum[i]!=0) printf("%d %d\n",i,sum[i]); printf("\n"); } return 0;}
0 0
- ZOJ 1610 线段树区间染色
- ZOJ 1610Count the Colors 线段树区间染色问题
- ZOJ 1610 Count the Colors (线段树区间染色)
- ZOJ 1610Count the Colors(线段树+区间染色)
- ZOJ 1610 Count the Colors(线段树区间染色)
- 【线段树区间更新 && 染色】ZOJ
- ZOJ-1610(区间染色)
- ZOJ 2301 Color the Ball 线段树 区间染色
- zoj 1610 Count the Colors 线段树区间更新——染色问题
- ZOJ 1610 Count the Colors(线段树——区间更新)(成段染色)
- zoj 1610(线段树染色问题)
- poj1436(线段树区间染色)
- poj2528(线段树区间染色)
- zoj 2301 Color the Ball(区间染色,线段树+离散化)
- ZOJ 1610 Count the Colors 线段树 染色问题
- zoj 1610 Count the Colors(线段树染色)
- 线段树-区间延迟修改-zoj-1610
- ZOJ-1610 线段树区间更新
- [leetcode]Remove Element
- DM8168 unrecoverable error: OMX_ErrorBadParameter (0x80001005) [resolved]
- Ubuntu 14.04 禁止可移动介质自动播放
- C# 文件操作及目录操作
- 重温JAVA(学习路线以及技术方向)
- ZOJ 1610 线段树区间染色
- 基于Luence的分布式搜索引擎ElasticSearch搜索实例演示(Java API)
- hdu 4472 递推
- 在 SQLite3 中使用回调函数
- 深入体验JavaWeb开发内幕——EL表达式之一
- gcc objdump 反汇编器
- 明日新星闪耀---致给FreshmanWSN嵌入式新人
- hdoj.1215 七夕节 20141030
- 补坑之路之两道容斥原理的基本模型题:HDU 4135&&HDU1796