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 这种情况 ...
随机推荐
- MVC验证11-对复杂类型使用jQuery异步验证
原文:MVC验证11-对复杂类型使用jQuery异步验证 本篇体验使用"jQuery结合Html.BeginForm()"对复杂类型属性进行异步验证.与本篇相关的"兄弟篇 ...
- 第4章3节《MonkeyRunner源码剖析》ADB协议及服务: ADB协议概览SYNC.TXT翻译参考(原创)
天地会珠海分舵注:本来这一系列是准备出一本书的,详情请见早前博文“寻求合作伙伴编写<深入理解 MonkeyRunner>书籍“.但因为诸多原因,没有如愿.所以这里把草稿分享出来,所以错误在 ...
- MVC多模板支持
参考: ASP.NET MVC:多模板支持
- Sql Server 存储过程中查询数据无法使用 Union(All)
原文:Sql Server 存储过程中查询数据无法使用 Union(All) 微软Sql Server数据库中,书写存储过程时,关于查询数据,无法使用Union(All)关联多个查询. 1.先看一段正 ...
- 机器学习学习-Types of learning
Types of learning 基于个人理解.于我们在面对一个详细的问题时.可以依据要达到的目标选择合适的机器学习算法来得到想要的结果.比方,推断一封电子邮件是否是垃圾邮件,就要使用分类(clas ...
- LeetCode之Reverse Words in a String
1.(原文)问题描述 Given an input string, reverse the string word by word. For example, Given s = "the ...
- html5 音频和视频(audio And video)
1.音频和视频 Web 上的视频 直到现在,仍然不存在一项旨在网页上显示视频的标准. 今天,大多数视频是通过插件(比如 Flash)来显示的.然而,并非所有浏览器都拥有同样的插件. HTML5 规定 ...
- 【UNIX网络编程(一)】套接字地址结构、网络字节顺序和地址转换功能
介绍:应该用在网络编程实现每个套接字地址结构.所以主套接字地址结构后前提网络计划编制,地址结构可以在两个方向上发送:从工艺到内核和内核处理.构中的二进制值之间进行转换. 大多数套接字函数都须要一个指向 ...
- NHProfiler使用方法
NHProfiler使用方法 NHProfiler是一个针对Nhibernate运行分析的工具. 使用如下: (1)在创建ISessionFactory的项目中引用NHProfiler安装目录下的Hi ...
- ThoughtWorks 面试
ThoughtWorks 面试备忘录 ThoughtWorks 面试备忘录 前言 前段时间 ThoughtWorks 在网上和拉勾网合作搞了一次网络招聘,名为抛弃简历!让代码说话!可谓赚足了眼球, ...