HDU 1566 Color the ball
来源:互联网 发布:qt软件怎么样 编辑:程序博客网 时间:2024/06/01 15:21
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19531 Accepted Submission(s): 9719
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
分析:其实这个题目就是poj2155的简化版,详见本人博客的poj2155;
代码如下:
#include<stdio.h>#include<string.h>int tree[100005];int t;void add(int x,int num){ for(int i=x;i<=t;i+=i&-i) tree[i]+=num;}int read(int x){ int sum=0; for(int i=x;i>0;i-=i&-i) sum+=tree[i]; return sum;}int main(){ int a,b; while(scanf("%d",&t),t) { memset(tree,0,sizeof(tree)); for(int i=0;i<t;i++) { scanf("%d%d",&a,&b); add(a,1); add(b+1,-1); } for(int i=1;i<t;i++) printf("%d ",read(i)); printf("%d\n",read(t)); } return 0;}
0 0
- HDU 1566 Color the ball
- HDU 1566 Color the ball
- HDU 1566 Color the ball
- Color the ball HDU
- Color the ball HDU
- Color the Ball HDU
- hdu 1566 Color the ball---线段树
- hdu 1556 color the ball
- hdu 1556Color the ball
- HDU 1556 - Color the ball
- hdu 1199 Color the Ball
- HDU 1199-Color the Ball
- Hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- hdu 1556 Color the ball
- calico配置 BGP Peers
- HDU1068 Girls and Boys(最大独立集)
- 良心发现?Win10将主动控制后台软件来省电
- SecureCRT&SecureFX(二):SecureCRT&SecureFX的简单操作教程
- github的几种加文件的方法
- HDU 1566 Color the ball
- 输入两个正整数m和n,求其最大公约数和最小公倍数
- 面向对象的陷阱——非静态内部类的陷阱
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- MATLAB之输出
- AngularJS常见内置指令以及控制器
- calico配置 BIRD 作为 BGP Route Reflector
- 【Android graphics】(一) Android SVG使用之AnimatedVectorDrawable
- hihoCoder #1014 : Trie树