http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610

https://vjudge.net/contest/318019#problem/F

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


Sample Output


这题题意不太好懂

题目大意:

在范围[0,8000]内,给n个操作,把[x,y]段染成颜色c,注意是线段不是点,最后按颜色从小到大输出每种颜色连续的线段的个数,有颜色的才输出;

先给出我参考的博客

https://www.cnblogs.com/kuangbin/archive/2012/08/10/2631449.html

https://www.cnblogs.com/thunder-110/p/10302782.html

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
const int maxn=1e5+;
using namespace std;
//ios::sync_with_stdio(false);
// cin.tie(NULL); int n;
int last;//flag判断相邻两个区间的颜色是否相同
struct node
{
int l;
int r;
int color;
}SegTree[<<]; int ans[<<]; void PushDown(int rt)
{
if(SegTree[rt].color>)
{
SegTree[rt<<].color=SegTree[rt].color;
SegTree[rt<<|].color=SegTree[rt].color;
SegTree[rt].color=-;
}
} void Build(int l,int r,int rt)
{
SegTree[rt].l=l;
SegTree[rt].r=r;
SegTree[rt].color=;//多样例时必须加
if(l==r)
{
return;
}
int mid=(l+r)>>;
Build(l,mid,rt<<);
Build(mid+,r,rt<<|);
} void Update(int L,int R,int C,int rt)
{
int l=SegTree[rt].l;
int r=SegTree[rt].r;
if(L<=l&&R>=r)
{
SegTree[rt].color=C;
return ;
}
PushDown(rt);//向下更新lazy
int mid=(l+r)>>;
if(L<=mid)//当寻找一个区间的时候,路径上的值全改成C
Update(L,R,C,rt<<);
if(R>mid)//当寻找一个区间的时候,路径上的值全改成C
Update(L,R,C,rt<<|);
SegTree[rt].color=-;//寻找到了之后,把回头的路径全部改成-1,说明如果顺着这些点下来,一定能找到区间
} void Query(int rt)
{
if(last==SegTree[rt].color)
return;
if(SegTree[rt].color==)//一次也没有被涂过
{
last=;
return;
}
if(SegTree[rt].color>)
{
if(last!=SegTree[rt].color)//不是同一块海报
{
last=SegTree[rt].color;
ans[SegTree[rt].color]++;
}
return;
}
//接下来是如果SegTree[rt].color== -1 ,表示顺着这个点 一定能找到区间
Query(rt<<);
Query(rt<<|);
} int main()
{
while(~scanf("%d",&n))
{
memset(ans,,sizeof(ans));
Build(,,);
for(int i=;i<=n;i++)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
Update(a,b-,c+,);
}
Query();
for(int i=;i<=;i++)
{
if(ans[i])
printf("%d %d\n",i-,ans[i]);
}
printf("\n");
}
return ;
}

暴力解法:

 #include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stack>
#include<ctype.h>
#include<stdlib.h>
#include<map>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int M=;
int main()
{
int n,t[M];
while(~scanf("%d",&n))
{
memset(t,-,sizeof(t));
int j,i,a,b,c,max1=-,max2=-;
int ans[M]= {};
for(i=; i<n; i++)
{
scanf("%d %d %d",&a,&b,&c);
max1=max(max1,b);//记录染有颜色的最右端
max2=max(max2,c);//记录染颜色的最大数值 for(j=a+; j<=b; j++)//注意这里,题目中的说的是线段,所以我们每次不标记最左端
t[j]=c;
}
for(i=; i<max1; i++)
{
if(t[i]!=t[i+]&&t[i]!=-)
ans[t[i]]++;
}
ans[t[max1]]++;
for(i=; i<=max2; i++)
{
if(ans[i]>)
printf("%d %d\n",i,ans[i]);
}
printf("\n");
}
return ;
}

ZOJ-1610 Count the Colors(线段树染色,求染色段)的更多相关文章

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

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

  2. ZOJ 1610 Count the Colors (线段树成段更新)

    题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...

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

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

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

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

  5. [ZOJ1610]Count the Colors(线段树,区间染色,单点查询)

    题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610 题意:给一个长8000的绳子,向上染色.一共有n段被染色,问染 ...

  6. ZOJ 1610 Count the Color(线段树区间更新)

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

  7. Count the Colors(线段树,找颜色段条数)

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

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

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

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

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

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

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

随机推荐

  1. 使用H5搭建webapp主页面

    使用H5搭建webapp主页面 前言: 在一个h5和微信小程序火热的时代,作为安卓程序员也得涉略一下h5了,不然就要落后了,据说在简历上可以加分哦,如果没有html和css和js基础的朋友,可以自行先 ...

  2. 理解String的intern()方法

    API文档中的介绍: intern public String intern() Returns a canonical representation for the string object. A ...

  3. grid布局——从入门到放弃

    基本知识 CSS grid 布局有两个核心组成部分:wrapper(网格容器,父元素)和items(网格项,子元素). 基本属性 属性 含义 display: grid 网格布局(父元素设置) gri ...

  4. UVA 11987 - Almost Union-Find 并查集的活用 id化查找

    受教了,感谢玉斌大神的博客. 这道题最难的地方就是操作2,将一个集合中的一个点单独移到另一个集合,因为并查集的性质,如果该点本身作为root节点的话,怎么保证其他点不受影响. 玉斌大神的思路很厉害,受 ...

  5. Centos7下yum安装软件报错解决办法

    Traceback (most recent call last): File "/usr/bin/yum", line 29, in yummain.user_main(sys. ...

  6. 通过geopandas.sjoin()函数按多边形范围分割点

    最近有一批点和多变型的数据,需要将点按照多边形的区域进行分割. 经过若干尝试,终于通过geopandas的sjoin函数得以实现. 这里首先感谢博主“张da统帅”的分享,使得本人获得该实现方法的灵感, ...

  7. 18 11 13 装了ssd 继续 网络通信 tcp 客户端的创建

    import socket def main(): # 1. 买个手机(创建套接字 socket) 联通公司建立了一个信号塔 tcp_server_socket = socket.socket(soc ...

  8. LINUX之ntp时间同步服务配置

    本篇将介绍LINUX之ntp服务配置,时钟同步服务器配置.这个在很多地方都会用到,保持各主机之前的时间保持一致,保证主机之间的心跳稳定. 三台主机都是centos7 192.168.1.110 mas ...

  9. mysql,apache,php的关系

    首先要明白动态网站与静态网站 所谓的动态网页,是指跟静态网页相对的一种网页编程技术.静态网页,随着html代码的生成,页面的内容和显示效果就基本上不会发生变化了——除非你修改页面代码.而动态网页则不然 ...

  10. 吴裕雄--天生自然Linux操作系统:Linux 忘记密码解决方法

    忘记Linux系统的root密码,linux系统忘记root密码的情况该怎么办呢?重新安装系统吗?当然不用!进入单用户模式更改一下root密码即可. 步骤如下: 重启linux系统 3 秒之内要按一下 ...