hdoj--1556--Color the ball(模拟&&树状数组)
Color the ball
Total Submission(s): 13727 Accepted Submission(s): 6903
当N = 0,输入结束。
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
1 1 1
3 2 1
先来一组大神的代码,真神奇的模拟,思路太好了
#include<stdio.h>
#include<string.h>
int num[1000010];
int main()
{
int n;
while(scanf("%d",&n),n)
{
memset(num,0,sizeof(num));
int m=0;
for(int i=0;i<n;i++)
{
int a,b;
scanf("%d%d",&a,&b);
num[a]++;
num[b+1]--;
}
for(int i=1;i<n;i++)
{
m+=num[i];
printf("%d ",m);
}
printf("%d\n",m+num[n]);
}
return 0;
}
树状数组
#include<stdio.h>
#include<string.h>
int num[100010];
int n;
void add(int x,int k)
{
while(x>=1)
{
num[x]+=k;
x-=x&(-x);
}
}
int sum(int x)
{
int s=0;
while(x<=n)
{
s+=num[x];
x+=x&(-x);
}
return s;
}
int main()
{
while(scanf("%d",&n),n)
{
memset(num,0,sizeof(num));
for(int i=0;i<n;i++)
{
int a,b;
scanf("%d%d",&a,&b);
add(b,1);
add(a-1,-1);
}
for(int i=1;i<=n;i++)
{
if(i>1)
printf(" ");
printf("%d",sum(i));
}
printf("\n");
}
return 0;
}
hdoj--1556--Color the ball(模拟&&树状数组)的更多相关文章
- hdu 1556 Color the ball(树状数组)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意:N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数[a,b]之间的气球 ...
- hdu 1556 Color the ball (树状数组)
Color the ballTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 1556 Color the ball (树状数组 区间更新+单点查询)
题目链接 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽&quo ...
- HDU 1556 Color the ball【树状数组】
题意:给出n个区间,每次给这个区间里面的数加1,询问单点的值 一维的区间更新,单点查询,还是那篇论文里面讲了的 #include<iostream> #include<cstdio& ...
- Color the ball(HDU1556)树状数组
每次对区间内气球进行一次染色,求n次操作后后所有气球染色次数. 树状数组,上下区间更新都可以,差别不大. 1.对于[x,y]区间,对第x-1位减1,第y位加1,之后向上统计 #include<b ...
- HDU 1556 Color the ball (数状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- hdu 1556 Color the ball 线段树
题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...
- HD1556Color the ball(树状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- WinServer-IIS-MIME类型
自定义类型的处理流程 1.浏览器问服务器,这是什么类型的文件 2.服务器告诉浏览器这是什么类型的文件(如果不告诉,那么浏览器就会下载相应文件) 3.浏览器告诉windows注册表这是什么类型的文件 4 ...
- 基于ORA-12170 TNS 连接超时解决办法详解
转自原文 基于ORA-12170 TNS 连接超时解决办法详解 1.开始----程序-----Oracle------配置和移植工具-----Net Manager----本地----服务命名---o ...
- spring mvc常用知识点总结
1.spring mvc是靠spring 启动的.通过springjar包的org.springframework.web.servlet.DispatcherServlet这个servlet类具体启 ...
- m_Orchestrate learning system---十一、thinkphp查看临时文件的好处是什么
m_Orchestrate learning system---十一.thinkphp查看临时文件的好处是什么 一.总结 一句话总结:可以知道thinkphp的标签被smarty引擎翻译而来的php代 ...
- nyoj--1023--还是回文(动态规划)
还是回文 时间限制:2000 ms | 内存限制:65535 KB 难度:3 描述 判断回文串很简单,把字符串变成回文串也不难.现在我们增加点难度,给出一串字符(全部是小写字母) ...
- vue 组件之间的传值
父向子传值父组件 <v-footer :projectdat="dat"></v-footer> export default { data() { ret ...
- URAL 1297 后缀数组+线段树
思路: 论文题--*n 倒过来接上 分奇偶讨论 求LCP 搞棵线段树即可 //By SiriusRen #include <cstdio> #include <cstring> ...
- requireJS实现原理分析
下面requireJS实现的基本思路 项目地址https://github.com/WangMaoling/require var require = (function(){ //框架版本基本信息 ...
- 从 MVC 到微服务,技术演变的必经之路
架构模式演进 CGI 模式 图 1 CGI 出现于 1993 年,图 1 是 CGI 模式比较简单的结构图. MVC 模式 开源电商软件等都是采用 MVC 模式,MVC 模式是做软件开发必学和必经历的 ...
- c# 02-18 值类型 引用类型 字符串的不可变性 字符串的处理方法
1值类型 直接把值存在栈中 栈的特点是后进先出 int double decimal char struct enum bool 2 引用类型 把值存在堆中,把地址存在栈中: string 自定义的类 ...