zoj 1610 Count the Colors
来源:互联网 发布:radialindicator.js 编辑:程序博客网 时间:2024/06/10 13:00
类型:一维线段树
来源:ZOJ Monthly, May 2003
题目:线段染色问题,求最后最上面的颜色段数思路:对每一次染色执行update操作,当颜色未完全覆盖当前段时,当前根的颜色块需要下移!然后执行一次query操作记录所有线段的颜色
数据:2
1 2 3
4 5 3结果为2
// zoj 1610// tle wa wa wa ac 90ms#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define FOR(i,a,b) for(i = (a); i < (b); ++i)#define FORE(i,a,b) for(i = (a); i <= (b); ++i)#define CLR(a,b) memset(a,b,sizeof(a))const int MAXN = 8010;const int MAXM = 8010;int n, a, b, c;int tree[4 * MAXN], cnt[MAXM], col[MAXM];void update(int root, int l, int r, int x1, int x2) { if(l == x1 && r == x2) { tree[root] = c; return ; } if(l == r - 1) return ; if(tree[root] != -1) { tree[root << 1] = tree[root]; tree[root << 1 | 1] = tree[root]; tree[root] = -1; } int mid = (l + r) >> 1; if(mid >= x2) update(root << 1, l, mid, x1, x2); else if(mid <= x1) update(root << 1 | 1, mid, r, x1, x2); else { update(root << 1, l, mid, x1, mid); update(root << 1 | 1, mid, r, mid, x2); }}void query(int root, int l, int r) { int i; if(tree[root] != -1) { FOR(i, l, r) col[i] = tree[root]; return ; } if(l == r - 1) return ; int mid = (l + r) >> 1; query(root << 1, l, mid); query(root << 1 | 1, mid, r);}int main() { int i; while(scanf("%d", &n) != EOF) { CLR(tree, -1), CLR(cnt, 0), CLR(col, -1); int maxc = -1, maxb = -1; FOR(i, 0, n) { scanf("%d %d %d", &a, &b, &c); maxc = max(maxc, c); maxb = max(maxb, b); update(1, 0, 8001, a, b); } int tmp = -1; query(1, 0, 8001); FOR(i, 0, maxb) { if(col[i] == -1) { tmp = -1; continue; } if(col[i] != tmp) ++cnt[col[i]], tmp = col[i]; } FORE(i, 0, maxc) if(cnt[i] != 0) printf("%d %d\n", i, cnt[i]); printf("\n"); } return 0;}/*21 4000 14000 6000 021 2 34 5 3*/
- zoj 1610 Count the Colors
- zoj 1610 Count the Colors
- ZOJ 1610 Count the Colors
- zoj 1610 Count the Colors
- zoj 1610 Count the Colors
- ZOJ 1610 Count the Colors
- zoj 1610 Count the Colors
- ZOJ 1610 Count the Colors
- zoj 1610 Count the Colors
- zoj 1610 Count the Colors
- ZOJ 1610 Count the Colors
- zoj 1610 Count the Colors
- ZOJ-1610 Count the Colors
- ZOJ 1610 Count the Colors
- 【ZOJ 1610】Count the Colors
- zoj 1610 Count the Colors
- ZOJ 1610Count the Colors
- Count the Colors(zoj 1610)
- 境外资源搜索引擎
- 我的美国CS面试经验分享 转自孙正立的人人日志
- ORA-02449: unique/primary keys in table referenced by foreign keys
- ubuntu关机、重启、注销命令行指令
- vb.net 无法读取app.config中的配置参数的解决方式
- zoj 1610 Count the Colors
- VS中Debug模式和Release模式的区别
- 湖北联通的综合营帐数据同步应用--案例
- RtlInitializeGenericTable系列函数的总结
- WM_DRAWITEM与DrawItem()的讨论
- 26字母起源二十六个英语字母的起源与含义
- Ubuntu进入文本模式后启动停在Checking battery state
- Ubuntu11.10 上安装CUDA开发环境
- Bitmap和Drawable相互转换方法