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 ...
随机推荐
- [Git] git代码统计
copy : https://www.cnblogs.com/liyropt/archive/2012/12/31/2841053.html 命令行 查看git上的个人代码量: git log --a ...
- [Git] git merge之squash
reference : https://www.cnblogs.com/ungshow/p/3515161.html 看CM源码时,发现历史记录里有很多squash,于是google了解了一下. Gi ...
- 日期时间篇asctime ctime gettimeofday gmtime localtime mktime settimeofday time
asctime(将时间和日期以字符串格式表示) 相关函数 time,ctime,gmtime,localtime 表头文件 #include<time.h> 定义函数 char * asc ...
- go语言之进阶篇同名字段
1.同名字段 示例: package main import "fmt" type Person struct { name string //名字 sex byte //性别, ...
- 关于asp.net页面缓存
1,ASPX页面缓存 页面缓存的使用方法非常的简单,只需要在aspx页的顶部加一句声明<%@ OutputCache Duration="60" VaryByParam=&q ...
- iframe多层嵌套时获取元素
一.同域:1.父页面获取子页面元素:注意:onload事件jQuery获取:$("iframe").contents().find("holder")..... ...
- golang struct转map
struct转map package main import ( "fmt" "reflect" "time" ) type User st ...
- 如何配置Ubuntu 16.04 GRUB 2引导加载程序
正如你所知,GRUB 2 是大多数 Linux 操作系统的默认引导加载程序.GRUB 是 GRand Unified Bootloader 的缩写,它是 Linux 启动时首先要加载的一个程序,此后它 ...
- 在陌生Linux环境查看Tomcat服务的方法
1.查看Tomcat进程 执行命令$ps -ef|grep tomcat 你就能找出tomcat占据的进程号,当然这要求tomcat启动了. # ps -ef | grep tomcatroot ...
- hadoop2.2.0_hbase0.96_zookeeper3.4.5全分布式安装文档下载
本文档主要内容有: 1.hadoop 2.2.0 集群安装与部署 2.HBase 0.96 集群安装与部署 3.Zookeeper 3.4.5集群安装部署 备注:安装文档可能有所遗漏,后续将持续更新. ...