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-AD操作常用powershell命令
powershell 操作AD常用命令 查询AD中默认的密码策略 Get-ADDefaultDomainPasswordPolicy 查询AD中密码永不过期的用户 Get-ADUser -Filter ...
- POJ 2480
可以容易得知,F=sum(p*phi(n/p)).思路就断在这里了... 看过别人的,才知道如下: 由于gcd(i,n*m)=gcd(i,m)*gcd(i,n),所以gcd为积性函数.而积性函数之和为 ...
- HDU 5410(2015多校10)-CRB and His Birthday(全然背包)
题目地址:HDU 5410 题意:有M元钱,N种礼物,若第i种礼物买x件的话.会有Ai*x+Bi颗糖果,现给出每种礼物的单位价格.Ai值与Bi值.问最多能拿到多少颗糖果. 思路:全然背包问题. dp[ ...
- Application Loader提交ipa文件出现ERROR ITMS-90022问题解决方式
话说在提交app到AppStore时出现了一些问题.网上找了一些资料,但不并具体.因此我做了一个总结,方便我以后遇到时可查询. 也希望能帮助遇到这个问题的提供解决方式. ERROR ITMS-9002 ...
- hdu 2604 Queuing (矩阵高速幂)
Queuing Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- thinkphp项目上传到github,为什么缺少很多文件
thinkphp项目上传到github,为什么缺少很多文件 问题: 把tp5项目push到码云(类似github)上,为什么没有thinkphp这个核心库? 然后我看了下码云和github上,官方的t ...
- [JZOJ 4307] [NOIP2015模拟11.3晚] 喝喝喝 解题报告
题目链接: http://172.16.0.132/senior/#main/show/4307 题目: 解题报告: 题目询问我们没出现坏对的连续区间个数 我们考虑从左到有枚举右端点$r$,判断$a[ ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串 C++实现java实现
最长无重复字符的子串 Given a string, find the length of the longest substring without repeating characters. Ex ...
- sql/plus无法显示数据库问题
登录PL/SQL Developer 这里省略Oracle数据库和PL/SQL Developer的安装步骤,注意在安装PL/SQL Developer软件时,不要安装在Program Files ( ...
- Linux mount挂载umount卸载
mount/umount挂载/卸载 对于Linux用户来讲,不论有几个分区,分别分给哪一个目录使用,它总归就是一个根目录.一个独立且唯一的文件结构 Linux中每个分区都是用来组成整个文件系统的一部分 ...