zoj 1610 Count the Colors
来源:互联网 发布:广西 人工智能 编辑:程序博客网 时间:2024/05/05 06:58
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.
Your task is counting the segments of different colors you can see at last.
Input
The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.
Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:
x1 x2 c
x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.
All the numbers are in the range [0, 8000], and they are all integers.
Input may contain several data set, process to the end of file.
Output
Each line of the output should contain a color index that can be seen from the top, following the count of the segments of this color, they should be printed according to the color index.
If some color can't be seen, you shouldn't print it.
Print a blank line after every dataset.
Sample Input
5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3
4
0 1 1
3 4 1
1 3 2
1 3 1
6
0 1 0
1 2 1
2 3 1
1 2 0
2 3 0
1 2 1
Sample Output
1 1
2 1
3 1
1 1
0 2
1 1
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <cstdlib>#include <limits>#include <queue>#include <stack>#include <vector>#include <map>using namespace std;#define N 80005#define INF 0xfffffff#define PI acos (-1.0)#define EPS 1e-8#define Lson rt<<1, l, tree[rt].mid ()#define Rson rt<<1|1, tree[rt].mid ()+1, rstruct node1 {int l, r, e;}post[N];struct node2{ int l, r, color; int mid (){return (l + r) / 2;}}tree[N * 4];int color[N], ans[N];void build (int rt, int l, int r);void Insert (int rt, int l, int r, int e);void update (int rt);int main (){ int n; while (~scanf ("%d", &n)) { for (int i=1; i<=n; i++) scanf ("%d%d%d", &post[i].l, &post[i].r, &post[i].e); build (1, 0, N-1); memset (color, -1, sizeof (color)); memset (ans, 0, sizeof (ans)); for (int i=n; i>0; i--) Insert (1, post[i].l+1, post[i].r, post[i].e); for (int i=0; i<N; i++) if (color[i] != -1 && (!i || color[i] != color[i-1])) ans[color[i]]++; for (int i=0; i<N; i++) if (ans[i]) printf ("%d %d\n", i, ans[i]); puts (""); } return 0;}void build (int rt, int l, int r){ tree[rt].l = l, tree[rt].r = r; tree[rt].color = 0; if (l == r) return; build (Lson), build (Rson);}void Insert (int rt, int l, int r, int e){ if (tree[rt].color == 1) return; if (!tree[rt].color && tree[rt].l == l && tree[rt].r == r) { tree[rt].color = 1; for (int i=l; i<=r; i++) color[i] = e; return; } else tree[rt].color = 2; if (r <= tree[rt].mid ()) Insert (rt<<1, l, r, e); else if (l > tree[rt].mid ()) Insert (rt<<1|1, l, r, e); else Insert (Lson, e), Insert (Rson, e); update (rt);}void update (int rt){ if (tree[rt].l != tree[rt].r) if (tree[rt<<1].color == 1 && tree[rt<<1|1].color == 1) tree[rt].color = 1;}
- 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)
- Servlet之doGet()和doPost()方法区别和联系【入门版,初学者必看】
- JavaWeb文件上传与下载
- crontab介绍 + 小示例 + crontab不执行的原因
- DEDEcms5.7+php5.4后台空白解决方法
- 净颜梅效果怎么样
- zoj 1610 Count the Colors
- 【安卓开发】安卓实用demo合集,有了这些一个项目轻松搞定
- 《构建之法》 –读书笔记
- iOS 文字属性字典
- 51 nod 1189 阶乘分数
- 在sqlserver2008中收缩日志文件
- Linux不能获取ip地址
- Exception from container-launch: org.apache.hadoop.util.Shell$ExitCodeException
- SSH2框架的搭建条件