77范文网 - 专业文章范例文档资料分享平台

acm数据结构题解

来源:网络收集 时间:2019-03-22 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

ZOJ1610

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

#include #include #include #include #include #include #include #include #include #include #define L(x) (x << 1)

#define R(x) (x << 1 | 1)

using namespace std;

const int MAX = 8010; struct Tnode{ int col; int l,r;}; Tnode node[MAX*3]; int col[MAX],len[MAX];; void init() {

memset(node,0,sizeof(node)); memset(col,-1,sizeof(col)); }

void Build(int t,int l,int r) {

node[t].l = l; node[t].r = r; node[t].col = -1; if( l == r - 1 ) return ; int mid = ( l + r ) >> 1; Build(L(t), l, mid); Build(R(t), mid, r); }

void Updata(int t,int l,int r,int col) {

if( node[t].l >= l && node[t].r <= r ) {

node[t].col = col; return ; }

if( node[t].col == col ) return ; if( node[t].col >= 0 ) {

node[R(t)].col = node[t].col; node[L(t)].col = node[t].col; node[t].col = -1; }

int mid = (node[t].l + node[t].r) >> 1; if( l >= mid )

Updata(R(t),l,r,col); else

if( r <= mid )

Updata(L(t),l,r,col); else {

Updata(L(t),l,mid,col); Updata(R(t),mid,r,col);

} }

void Compute(int t,int l,int r) {

if( node[t].col >= 0 ) {

for(int i=l; i

if( node[t].l == node[t].r - 1 ) return ;// 如果父亲节点已经是这种颜色了,就没必要再染色了

int mid = (node[t].l + node[t].r) >> 1; if( l >= mid )

Compute(R(t),l,r); else

if( r <= mid )

Compute(L(t),l,r); else {

Compute(L(t),l,mid); Compute(R(t),mid,r); } }

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库acm数据结构题解在线全文阅读。

acm数据结构题解.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/535943.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: