http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610

 Count the Colors

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

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//第0个区间涂颜色1
3 4 1//第3个区间涂颜色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次操作后问每种颜色在线段上有多少个间断的区间

这道题可用线段树写,

 (0, 1)为区间0,(1, 2)为区间1,,(2, 3)为区间2   ...
 
该代码未用线段树,用一般方法写的
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
#define N 8010 using namespace std; int color[N], counts[N];
int main()
{
int n, i, a, b, c, Min, Max;
while(scanf("%d", &n) != EOF)
{
memset(color, -, sizeof(color));//记录区间被涂的颜色
memset(counts, , sizeof(counts));//记录每种颜色的区间个数
Min = INF;
Max = -INF;
while(n--)
{
scanf("%d%d%d", &a, &b, &c);
Min = min(a, Min);
Max = max(b, Max);
for(i = a ; i < b ; i++)
color[i] = c;//第i个区间被涂上类型为c的颜色
}
for(i = Min + ; i <= Max - ; i++)
if(color[i] != color[i - ] && color[i - ] != -)
counts[color[i - ]]++;//统计每种颜色的个数
if(color[i - ] != -)
counts[color[i - ]]++;
for(i = ; i < N ; i++)
if(counts[i] != )
printf("%d %d\n", i, counts[i]);//i表示颜色种类,counts[i]涂i种颜色的区间个数
printf("\n");
}
return ;
}
 

zoj 1610 Count the Colors的更多相关文章

  1. ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】

    任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...

  2. ZOJ 1610——Count the Colors——————【线段树区间替换、求不同颜色区间段数】

    Count the Colors Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  3. zoj 1610 Count the Colors 线段树区间更新/暴力

    Count the Colors Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

  4. zoj 1610 Count the Colors 【区间覆盖 求染色段】

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  5. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  6. ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  7. ZOJ 1610 Count the Colors (线段树区间更新与统计)

    Painting some colored segments on a line, some previously painted segments may be covered by some th ...

  8. zoj 1610 Count the Colors(线段树延迟更新)

    所谓的懒操作模板题. 学好acm,英语很重要.做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意.最后确定了是线段树延迟更新果题.我就欣欣然上手敲了出来. 然后是漫长的段错误.... 第一次 ...

  9. ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)

    1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...

随机推荐

  1. Android开发之获取时间SystemClock

    转载:http://blog.csdn.net/tianfeng701/article/details/7562359 在Andriod中关于线程一部分中经常会遇到计算时间的操作,这里面应用较多的是S ...

  2. 在ASP.NET中如何判断用户IE浏览器的版本

    f ( Request.Browser.MajorVersion == ) { // to do } ................................................. ...

  3. svn 提交失败 更新失败 提示 已经锁定

      出现问题的原因:在上传的时候,由于网络掉线,导致svn提交到一半就没有反应了,这个时候我点击了取消,再之后无论是进行 更新还是提交,都提示 已经锁定 解决方法:在项目的空白地方,点击SVN  清理 ...

  4. xcode6.3 编译ffmpeg 2.6.3(已验证编译成功)

    1.解压ffmpeg2.6.3源代码,在根目录下新建文件myconfig,内容如下,执行命令chmod 777 ./myconfig 2../myconfig 3.make 4.make instal ...

  5. kendo grid输入框验证方法

    $("#grid").kendoGrid({ dataSource: dataSrc, //toolbar: ["save", "取消"], ...

  6. UVA 350 Pseudo-Random Numbers 伪随机数(简单)

    题意:给定Z, I, M,  L,根据随机数产生式k=(Z*L+I)%M.但是L表示的是上一个产生的数,比如根据产生式产生了序列{2,5,4,3}那么5是由L=2算来的,4由L=5算来的..第1个所产 ...

  7. $http POST 转字符串

  8. Java [Leetcode 318]Maximum Product of Word Lengths

    题目描述: Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where ...

  9. .Net中的各种序列化

    我们知道将对象的状态保持在存储媒体中,以便可以在以后重新创建精确的副本这正是数据持久化所要做的.而且,不同应用程序之间的通讯需要相互传输数据.那么序列化和反序列化正是为此而生. 序列化和反序列化 所谓 ...

  10. windows配置jdk

    一.JDK1.6下载 目前JDK最新版本是JDK1.6,到http://java.sun.com/javase/downloads/index.jsp可以下载JDK1.6. 二.JDK1.6安装 JD ...