HDUOJ-----1556Color the ball
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6787 Accepted Submission(s): 3549
个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <=
b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜
色了,你能帮他算出每个气球被涂过几次颜色吗?
当N = 0,输入结束。
代码:
/*@coder龚细军*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 100004
int ss[maxn],n;
int lowbit(int x)
{
return x&(-x);
}
void ope(int a,int b)
{
while(a<=n)
{
ss[a]++;
a+=lowbit(a);
}
b++; //因为b这个位置,也在a~b内,所以要上一位..
while(b<=n)
{
ss[b]--;
b+=lowbit(b);
}
//这样 这统计了a+b段,相当于{a,n}-{b,n}=={a,b}
}
int sum(int a)
{
int ans=;
while(a>)
{
ans+=ss[a];
a-=lowbit(a);
}
return ans;
}
int main()
{
int a,b,i;
while(scanf("%d",&n),n)
{
memset(ss,,sizeof(int)*(n+));
for(i=;i<n;i++)
{
scanf("%d %d",&a,&b);
ope(a,b);
}
for(i=;i<n;i++)
{
printf("%d ",sum(i));
}
printf("%d\n",sum(n));
}
return ;
}
HDUOJ-----1556Color the ball的更多相关文章
- HDUOJ -----Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- AOJ 0033 Ball【DFS】
有一个筒,从A口可以放球,放进去的球可通过挡板DE使其掉进B管或C管里,现有带1-10标号的球按给定顺序从A口放入,问是否有一种控制挡板的策略可以使B管和C管中的球从下往上标号递增. 输入: 第一行输 ...
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- var ball0=new Ball("executing") 是怎样被执行的?
function Ball(message){ alert(message); }; var ball0=new Ball("executing"); //var ball0=ne ...
- blue and red ball
#include<iostream> #include<cstring> using namespace std; int sum; ]; int n; int head; i ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- HD1556Color 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(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...
随机推荐
- C#常使用的正则表达式
/// <summary> /// 是否为手机号码 /// </summary> /// <param name="value"></pa ...
- 批处理bat一键安装APK
批处理bat一键安装APK 2018年10月11日 10:48:28 xyzshenxiang 阅读数:77 在安装apk时,每次都得拷贝到手机内存中,然后在手机上操作安装这样做非常不方便,下面介 ...
- Linux下分割、合并PDF(pdftk),用于Linux系统的6款最佳PDF页面裁剪工具
Linux下分割.合并PDF(pdftk),用于Linux系统的6款最佳PDF页面裁剪工具 Linux下分割.合并PDF(pdftk) pdftk http://www.pdflabs.com/doc ...
- Common Internet File System
CIFS (Common Internet File System) is a protocol that gained popularity around the year 2000, as ven ...
- JSTORM使用笔记
安装部署 zeromq 简单快速的传输层框架,安装如下: wget http://download.zeromq.org/zeromq-2.1.7.tar.gztar zxf zeromq-2.1.7 ...
- linux进程、调度、线程、进程上下文等几点理解
1.信号来自进程或内核 2.线程共享进程的代码空间和数据空间(全局变量或静态变量),文件描述符,信号,以及malloc分配的内存,每个线程拥有独立的栈空间和程序计数器,在创建线程时,调用pthread ...
- SQL Server’s Storage Top 10 Best Practices
好文章, 简明扼要. Storage Top 10 Best Practices http://technet.microsoft.com/en-us/library/cc966534.aspx
- RichTextBox 清空
this.tbContent.Document.Blocks.Clear();
- ECMAScript5之Object学习笔记(三)
第三部分继续... Object.getOwnPropertyDescriptor(obj, prop) 获取一个对象的属性描述符 根据"Own"这个词我们可以猜到,prop只能是 ...
- 【UI设计】扁平化设计之流行色值
收集了一些颜色值 顏色表示方法: 以命名方式定义经常使用的顏色,如color="green".可是自由度较低,何况单词量...... 以RGB值表示.如#FF0000表示red(红 ...