Count The colors_zoj1610_线段树
来源:互联网 发布:淘宝大魔王是真是假 编辑:程序博客网 时间:2024/06/03 16:54
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
翻完一堆英语,讲讲题目大意
已知有n条不同颜色的线段且新线段可以覆盖在旧线段上。求各颜色的线段各出现多少次
思路:
颜色覆盖!线段树!color记录当前节点的颜色,最后统计输出。比较简单而且和例3类似就不细说了。
源代码/pas:
typetree=record l,r,c:longint;end;var tmp,n:longint; t,g:array[0..40000]of tree; ans:array[0..10000]of longint;procedure insert(f,x,y,color:longint);var mid:longint;begin mid:=(t[f].l+t[f].r)div 2; if (t[f].c<>-1)and(t[f].l+1<>t[f].r) then begin t[f*2].c:=t[f].c; t[f*2+1].c:=t[f].c; end; if t[f].l+1<>t[f].r then t[f].c:=-1; if (x=t[f].l)and(y=t[f].r) then t[f].c:=color else begin if (x>=mid) then insert(f*2+1,x,y,color) else if (y<=mid) then insert(f*2,x,y,color) else begin insert(f*2,x,mid,color); insert(f*2+1,mid,y,color); end; end;end;procedure count(f:longint);var mid:Longint;begin if t[f].c<>-1 then begin if tmp<>t[f].c then begin inc(ans[t[f].c]); tmp:=t[f].c; end; exit; end; if t[f].l+1<>t[f].r then begin count(f*2); count(f*2+1); end else tmp:=-1;end;procedure build(f:longint);var mid:longint;begin if t[f].r-t[f].l=1 then exit; mid:=(t[f].l+t[f].r)div 2; t[f*2].l:=t[f].l; t[f*2].c:=t[f].c; t[f*2].r:=mid; t[f*2+1].l:=mid; t[f*2+1].r:=t[f].r; t[f*2+1].c:=t[f].c; build(f*2); build(f*2+1);end;procedure init;var n,m,i,j,x,y,z:longint;begin t[1].l:=0; t[1].r:=8000; t[1].c:=-1; build(1); g:=t; while not eof do begin readln(m); for i:=1 to m do begin readln(x,y,z); insert(1,x,y,z); end; tmp:=-1; count(1); for i:=0 to 8001 do if ans[i]<>0 then writeln(i,' ',ans[i]); writeln; t:=g; fillchar(ans,sizeof(ans),0); end;end;begin init;end.
- Count The colors_zoj1610_线段树
- ZOJ1610 Count the Colors,线段树
- ZOJ 1610Count the Colors//线段树
- zoj 1610 Count the Colors【线段树】
- zoj 1610 Count the Colors[线段树]
- 【线段树】Count the Colors (zoj 1610)
- zoj 1610 Count the Colors(线段树)
- zoj1610 Count the Colors(线段树)
- zoj 1610 Count the Colors 线段树
- 线段树之ZOJ1610 Count the Colors
- ZOJ - 1610 Count the Colors(线段树)
- ZOJ 1610 Count the Colors【线段树】
- zoj 1601 Count the Colorst(线段树)
- Count the Colors(线段树染色)
- ZOJ----1610-Count the Colors(线段树)
- zoj1610( 线段树)(Count the Colors)
- ZJU 1610 Count the Colors 线段树
- zoj 1610 Count the Colors(线段树)
- UVA - 11054 Wine trading in Gergovia
- SDUT3334数据结构实验之栈七:出栈序列判定
- 线上遇到插入重复数据(重复提交)
- hdu1269 迷宫城堡(tarjan入门)
- Notification用法,注意API版本,API大于11的setLatestEventInfo()方法已经不适用
- Count The colors_zoj1610_线段树
- 【Java基础】面向对象特性
- matlab 函数
- php curl函数免ssl校验
- 初始博弈【二】Nim(hdu 1849,poj1704)
- HDU 2457DNA repair
- 关联规则挖掘 ---- Apriori算法与CBA算法
- ACM程序设计选修课——Problem E:(ds:图)公路村村通(优先队列或sort+克鲁斯卡尔+并查集优化)
- 经典算法51(来测测你的编程基础)