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 ...
随机推荐
- linux 复制目录结构,但不复制文件
find src -type d | sed 's/src/mkdir -p dst/'|sh
- 使用SGD(Stochastic Gradient Descent)进行大规模机器学习
原贴地址:http://fuliang.iteye.com/blog/1482002 其它参考资料:http://en.wikipedia.org/wiki/Stochastic_gradient_ ...
- Sublime Text2格式化HMTL/CSS/JS插件HTML-CSS-JS Prettify
之前格式化用过JSFormat,今天在GitHub发现了一个比较好的插件HTML-CSS-JS Prettify,具体的地址https://github.com/victorporof/Sublime ...
- 浅议 android下的context
android学习中,最开始学习的一个类是activities,你是否知道他与context之间 的关系,我们经常用startactivities来唤起一个activities他的定义有在哪里了,他是 ...
- 【架构】SpringCloud 注册中心、负载均衡、熔断器、调用监控、API网关示例
示例代码: https://github.com/junneyang/springcloud-demo 参考资料: SpringCloud系列 Eureka 一句话概括下spring框架及spring ...
- 机器学习的开源平台 TensorFlow
一. google第二代人工智能机器学习开源工具. http://www.tensorfly.cn/ 二. 知乎上关于机器学习的资料问答 https://www.zhihu.com/question/ ...
- (算法)Trapping Rain Water II
题目: Given n * m non-negative integers representing an elevation map 2d where the area of each cell i ...
- activemq无法启动且后台管理界面进不去的解决办法
从官网下载了一个最新的activemq,目前最新版本是5.14.5 我下载的是windows版本,通过执行%activemq home%/bin/win64/InstallService.bat,可以 ...
- ZH奶酪:Windows7+VirtualBox安装Ubuntu虚拟机问题总结
1.下载VirtualBox(我的是4.3.26版本) https://www.virtualbox.org/ 2.下载Ubuntu ISO文件(我的是ubuntu-14.04-desktop-amd ...
- Android 之开发积累
1.后台设置ImageView的src属性 有三种方式:img = (ImageView)this.findViewById(R.id.img_result_analyze); [1]setImage ...