Count the Colors(区间更新,暴力)
来源:互联网 发布:淘宝盗图处罚规则2016 编辑:程序博客网 时间:2024/06/07 19:48
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
题意有点坑,染色的不是单点,是区间:1-5染1号,1-3染2号,4-5染3号最后露出来的有三个颜色区间;1-3,2号;3-4,1号;4-5,3号;
好多人用线段树,我用暴力就直接过了,注意每个样例之间有空行;说实话,用线段树还真不会写,还要继续学习;
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>#define MAX 8000+5using namespace std;int line[MAX];int main(){ int n; while((scanf("%d",&n))!=EOF){ int max1=0, max2=0; memset(line, -1, sizeof(line)); for(int i=1; i<=n; i++){ int x, y, c; scanf("%d%d%d",&x,&y,&c); max1=max(max1, y); max2=max(max2, c); for(int j=x+1; j<=y; j++) //注意把区间染色,不是把点染色; line[j]=c; } int cnt[MAX]; memset(cnt, 0, sizeof(cnt)); for(int i=0; i<max1; i++){ if(line[i]!=-1 && line[i]!=line[i+1]) cnt[line[i]]++; } cnt[line[max1]]++; for(int i=0; i<=max2; i++) if(cnt[i]) printf("%d %d\n",i, cnt[i]); printf("\n"); } return 0;}
- Count the Colors(区间更新,暴力)
- Count the Colors(暴力)
- ZOJ 1610Count the Colors 线段树_区间更新
- Count the Colors(线段树之区间成段更新)
- ZOJ 1610 Count the Colors(线段树区间更新)
- ZOJ1610 Count the Colors(线段树区间更新)
- zoj 1610 Count the Colors(线段树 区间更新)
- 大二训练第二周 Count the Colors 线段区间更新
- ZOJ 1610 Count the Colors (线段树区间更新)
- zoj 1610 Count the Colors(线段树 区间更新)
- zoj 1610 Count the Colors 线段树 区间更新
- Count the Colors (线段树,区间更新)
- 【线段树区间更新】Count the Colors ZOJ
- zoj 1610 Count the Colors【暴力乱搞】
- zoj 1610 Count the Colors 【暴力】
- Count the Colors (线段树,暴力)
- ZOJ 1610 Count the Colors(线段树成端更新,暴力水过)
- 非结构体线段树版 ZJU 1610 Count the Colors (线段树区间更新)
- Java定时任务关闭
- 基于拉链法的散列表(c++版)
- JAVA 水仙花数
- 利用数组模拟栈实现简单的表达式中缀转后缀并进行计算
- ImageView宽度填满屏幕,高度自适应
- Count the Colors(区间更新,暴力)
- Problems & Solutions -- 5. divisions in python2 & 3
- xib的屏幕适配问题
- AbstractQueuedSynchronizer类源码解析
- javaseday17(Vector 链表模拟队列或者堆栈 ArrayList 拆装箱 哈希)
- Java的自动装箱与拆箱机制
- unity:C#控制人在真实环境中行走
- 仿美团等APP城市选择
- 个人保存的一些IT资料网站