Color the ball(杭电1556)
来源:互联网 发布:mac如何下载魔兽世界 编辑:程序博客网 时间:2024/06/05 14:18
Color the ball
Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 8 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
Input
每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。
当N = 0,输入结束。
Output
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
Sample Input
31 12 23 331 11 21 30
Sample Output
1 1 13 2 1
/*树状数组应用。 */#include<stdio.h>#include<string.h> int n,tree[100010];int lowbit(int N){return N&(-N);}int add(int i,int t)//求第i个数之后都加上t. {while(i<=n){tree[i]+=t;i+=lowbit(i);}}int sum(int m) {int sum=0;while(m>0){sum+=tree[m];m-=lowbit(m);}return sum;}int main(){int i,a,b;while(scanf("%d",&n),n){memset(tree,0,sizeof(tree));for(i=0;i<n;i++){scanf("%d %d",&a,&b);add(a,1); //将a之后的涂色次数加1. add(b+1,-1);//将b之后的涂色次数减1. }printf("%d",sum(1));for(i=2;i<=n;i++) printf(" %d",sum(i));printf("\n");}return 0;}
0 0
- Color the ball(杭电1556)
- 杭电1556-Color the ball
- 杭电1556Color the ball
- 杭电1556 Color the ball
- 杭电1556 Color the ball
- 杭电1556 Color the ball(树状数组)
- 【杭电oj】1556 - Color the ball(区间更新)
- 【杭电-oj】-1556-Color the ball(区间更新)
- HDU--杭电--1556--Color the ball--线段树
- 两端标记法 - Color the ball -杭电1556
- 杭电 OJ Color the ball 树状数组
- hdu(1556)Color the ball
- HDU 1556 Color the ball (模拟)
- HDU 1556 Color the ball(BIT)
- 1556 Color the ball(分块)
- HDOJ 1556 Color the ball
- hdu 1556 color the ball
- hdu 1556Color the ball
- Happy BirthDay to You
- javascript与浏览器的数据交互
- java.lang.IllegalThreadStateException 线程运行报错
- 第九周项目4 九九乘法表
- 接触Python(x,y)
- Color the ball(杭电1556)
- Android学习日记(1)
- How to Slim Your Thighs with 5 Thigh Firming Exerc
- 第25题 Simplify Path
- ubuntu 14.04 eclipse 新建C项目
- 黑马训练营--IOS学习---OC语言学习总结1
- hdu-1087
- 黑马训练营--IOS学习---OC语言学习总结2
- 黑马训练营--IOS学习---OC语言学习总结3