zoj 1610 Count the Colors

时间:2023-01-26 07:38:29

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【题意&plus;线段树区间更新&amp&semi;&amp&semi;单点查询】

    任意门: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 线段树区间更新&sol;暴力

    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&lpar;线段树&comma;区间覆盖&comma;单点查询&rpar;

    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. visual studio自动导入 using 的快捷键

    快捷键是  shift + alt + f10 ,从 vs 2012开始 还增加了 ctrl+.  功能名称叫: 视图.显示智能标记

  2. 利用python将二值csv格式转换为矩阵

    #!/usr/bin/env python # coding:utf-8 #import pandas as pd, numpy as np; ''' 将csv文件转换为对应的邻接矩阵mat ''' ...

  3. 【转】Cordova文件传输插件fileTransfer

    任务要求: 访问手机的目录,选择一个文件,并使用该插件将指定文件传输到远程主机的某个指定目录中. HTML <!DOCTYPE html> <!-- Licensed to the ...

  4. java删除指定目录及其文件

    import java.io.File; public class Test { public static void main(String args[]){ Test t = new Test() ...

  5. XML文件操作指南

    一.XML简介 XML的全名是eXtensible Markup Language(可以扩展的标记语言),它的语法类似HTML,都是用标签来描述数据.HTML的标签是固定的,我们只能使用.不能修改: ...

  6. 【转】深入理解Java内存模型(三)——顺序一致性

    数据竞争与顺序一致性保证 当程序未正确同步时,就会存在数据竞争.java内存模型规范对数据竞争的定义如下: 在一个线程中写一个变量, 在另一个线程读同一个变量, 而且写和读没有通过同步来排序. 当代码 ...

  7. execl csv导出

    方维js方法:function export_csv() { var inputs = $(".search_row").find("input:[type!='chec ...

  8. OGG数据仓库以及单向复制(二)

    Configure Extract(提取)      Process in Source system 配置capture(捕获)参数 Edit extract process parameter G ...

  9. 如何关闭WIN7自动配置 IPV4 地址 169&period;254

    如何关闭WIN7自动配置 IPV4 地址 169.254 以管理员身份运行cmd.exe 输入:netsh winsock reset catalog 回车 输入:netsh int ip reset ...

  10. 2018-01-15 Antlr4&colon; 修改语法规则更接近普通BNF格式

    经 @沈默 在上文Antlr4添加中文变量赋求值,括号,各种问题评论中指出, 语法规则描述依赖于Antlr4生成的语法分析器的默认分析方法, 比如运算符的左联系, 以及优先级处理等等. 于是将语法修改 ...