hdu1556--Color the ball
来源:互联网 发布:淘宝码数图表制作 编辑:程序博客网 时间:2024/05/16 01:37
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8883 Accepted Submission(s): 4542
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
Author
8600
Source
HDU 2006-12 Programming Contest
Recommend
LL | We have carefully selected several similar problems for you: 1166 1542 1394 1698 1255
用数组k,k[i]表示对i到n的染色次数,求x点染色次数,将k[1]累加到k[x]
对于k数组的处理,如果输入(a,b)代表着k[a]+1 , k[b+1]-1;这样计算b以后的气球时这次的染色会被平衡掉
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int c[100010] ;int lowbit(int x){ return x & -x ;}void add(int i,int n,int d){ while(i <= n ) { c[i] += d ; i += lowbit(i) ; }}int sum(int i){ int a = 0 ; while( i ) { a += c[i] ; i -= lowbit(i) ; } return a ;}int main(){ int i , n , a , b ; while(scanf("%d", &n) && n ) { memset(c,0,sizeof(c)); for(i = 0 ; i < n ; i++) { scanf("%d %d", &a, &b); add(a,n,1); add(b+1,n,-1); } for(i = 1 ; i <= n ; i++) { a = sum(i); if(i == n) printf("%d\n", a); else printf("%d ", a); } } return 0;}
0 0
- hdu1556 color the ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- HDU1556 Color the ball
- hdu1556 Color the ball
- hdu1556--Color the ball
- Color the ball HDU1556
- HDU1556 Color the ball
- hdu1556 Color the ball
- HDU1556-----Color the ball
- hdu1556 Color the Ball
- HDU1556-color the ball
- HDU1556 Color the ball
- hdu1556 Color the ball
- Color the ball||HDU1556
- HDU1556 Color the ball
- HDU1556 Color the ball(线段树)
- Threejs 中建立可看到其内部的房间效果
- 80. Domino Internet Password
- linux 虚拟机中 配置IP 和主机名 永久生效
- 如果做一个循环滚动的UIScrollView
- 关于Arrays.asList(T... a)方法的使用注意事项
- hdu1556--Color the ball
- 简单实现一个Android ListView分类
- MongoDB数据库的安装
- 杨辉三角
- [ACM] ZOJ 3725 Painting Storages (DP计数+组合)
- hdu 1008
- java基础之细节(1)
- C++ STL中哈希表 hash_map介绍
- Websphere优化 (四个方面)举例