zoj 1610 Count the Colors(线段树延迟更新)
所谓的懒操作模板题。
学好acm,英语很重要。做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意。最后确定了是线段树延迟更新果题。我就欣欣然上手敲了出来。
然后是漫长的段错误。。。。
第一次看见这种错误,还不知道什么意思,在那儿瞎改了好久也没过。最后看了下别人的代码,才知道这个题不管给的n是几,建树都是按0~8000建树。。。。
亏我第一次提交之前还跟yyf商量说这道题的n很奇怪,怎么又两个意思。。。。
我的zoj第一题。
#include<stdio.h>
#include<string.h>
#define N 8005
struct node
{
int x,y;
int flag;
}a[N*3];
int mark[N];
void CreatTree(int t,int x,int y)
{
a[t].x=x;
a[t].y=y;
a[t].flag=-1;
if(x==y)
return ;
int temp=t*2;
int mid=(x+y)/2;
CreatTree(temp,x,mid);
CreatTree(temp+1,mid+1,y);
return ;
}
void InsertTree(int t,int x,int y,int k)
{
if(a[t].x==x&&a[t].y==y)
{
a[t].flag=k;
return ;
}
int temp=t*2;
int mid=(a[t].x+a[t].y)/2;
if(a[t].flag!=-1)
{
a[temp].flag=a[t].flag;
a[temp+1].flag=a[t].flag;
a[t].flag=-1;
}
if(y<=mid)
InsertTree(temp,x,y,k);
else if(x>mid)
InsertTree(temp+1,x,y,k);
else
{
InsertTree(temp,x,mid,k);
InsertTree(temp+1,mid+1,y,k);
}
return ;
}
int FindTree(int t,int x)
{
if(a[t].x==a[t].y)
return a[t].flag;
int temp=t*2;
int mid=(a[t].x+a[t].y)/2;
if(a[t].flag!=-1)
{
a[temp].flag=a[t].flag;
a[temp+1].flag=a[t].flag;
a[t].flag=-1;
} if(x<=mid)
return FindTree(temp,x);
else
return FindTree(temp+1,x);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
CreatTree(1,1,8001);
int i;
for(i=1;i<=n;i++)
{
int x,y,k;
scanf("%d%d%d",&x,&y,&k);
int temp;
if(x>y)
{
temp=x;
x=y;
y=temp;
}
x++;
InsertTree(1,x,y,k);
}
memset(mark,0,sizeof(mark));
int t=-1;
for(i=1;i<=8001;i++)
{
int temp;
temp=FindTree(1,i);
if(temp==t)
continue;
else if(temp!=t&&temp!=-1)
mark[temp]++;
t=temp;
}
for(i=0;i<=8001;i++)
{
if(mark[i]!=0)
printf("%d %d\n",i,mark[i]);
}
printf("\n");
}
return 0;
}
zoj 1610 Count the Colors(线段树延迟更新)的更多相关文章
- zoj 1610 Count the Colors 线段树区间更新/暴力
Count the Colors Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- ZOJ 1610 Count the Color(线段树区间更新)
描述Painting some colored segments on a line, some previously painted segments may be covered by some ...
- ZOJ 1610 Count the Colors (线段树成段更新)
题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
- hdu 5023 线段树延迟更新+状态压缩
/* 线段树延迟更新+状态压缩 */ #include<stdio.h> #define N 1100000 struct node { int x,y,yanchi,sum; }a[N* ...
- ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】
任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
- ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)
1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...
随机推荐
- [Unity3D]Unity3D游戏开发之刀光剑影特效的实现
大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei. 我实在不明确有的人为什么不喜欢武侠/仙侠类游戏,也许是因为武侠/仙侠类游戏身上被永远烙上的国 ...
- nodejs 平台的 webscoket 的实现
新手入门,没办法,只能选择不断不断的google吧. 找了很多的例子都跑不了,不知道什么原因. 后,自己在git搜索吧,选择了一个下面的例子: nodejs-web-socket 经过我的改造,改成我 ...
- PHP 6:PHP 基本数据类型
原文:PHP 6:PHP 基本数据类型 本章将介绍PHP基本类型.相信我们已经熟悉了C/C++,C#或者Java里的任意一种语言.本章会以C#为比较语言.OK,如果你想学PHP,你最先考虑的是什么呢? ...
- OCP-1Z0-051-题目解析-第9题
9. Which statement is true regarding the INTERSECT operator? A. It ignores NULL values. B. Reversing ...
- Spring之单元测试
引言 是否在程序运行时使用单元测试是衡量一个程序员素质的一个重要指标.使用单元测试既可以让我检查程序逻辑的正确性还可以让我们减少程序测试的BUG,便于调试可以提高我们写程序的效率.以前我们做单元测试的 ...
- How To : Create SQL Server Management Studio Addin
原文 How To : Create SQL Server Management Studio Addin Read the full and original article from Jon Sa ...
- 自己动手实现Expression翻译器 – Part Ⅱ
上一节我们了解了Linq查询大体上是如何运转的,并针对SQL表达式进行建模(DbExpression),这一节的重点在于如何将表达式转换为DbExpression. 可以说只要能生成结构清晰的DbEx ...
- 图片轮播插件Nivo Slider
推荐:图片轮播插件Nivo Slider 因为项目需要一款切换样式多一些的轮播插件,不经意找到了NivoSlider,非常好用,比bootstrap要好用,而且样式丰富.值得注意的是, ...
- Markdown 代码测试!
# Mou  ## Overview **Mou**, the missing Markdown editor fo ...
- UVA 10391 Compound Words
Problem E: Compound Words You are to find all the two-word compound words in a dictionary. A two-wor ...