hdoj--1556--Color the ball(模拟&&树状数组)
来源:互联网 发布:php文章源码 编辑:程序博客网 时间:2024/06/04 18:22
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13727 Accepted Submission(s): 6903
Total Submission(s): 13727 Accepted Submission(s): 6903
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: 1542 1394 1698 1255 2795
先来一组大神的代码,真神奇的模拟,思路太好了
树状数组
先来一组大神的代码,真神奇的模拟,思路太好了
#include<stdio.h>#include<string.h>int num[1000010];int main(){int n;while(scanf("%d",&n),n){memset(num,0,sizeof(num));int m=0;for(int i=0;i<n;i++){int a,b;scanf("%d%d",&a,&b);num[a]++;num[b+1]--;}for(int i=1;i<n;i++){m+=num[i];printf("%d ",m);}printf("%d\n",m+num[n]);}return 0;}
树状数组
#include<stdio.h>#include<string.h>int num[100010];int n;void add(int x,int k){while(x>=1){num[x]+=k;x-=x&(-x);}}int sum(int x){int s=0;while(x<=n){s+=num[x];x+=x&(-x);}return s;}int main(){while(scanf("%d",&n),n){memset(num,0,sizeof(num));for(int i=0;i<n;i++){int a,b;scanf("%d%d",&a,&b);add(b,1);add(a-1,-1);}for(int i=1;i<=n;i++){if(i>1)printf(" ");printf("%d",sum(i));}printf("\n");}return 0;}
0 0
- hdoj--1556--Color the ball(模拟&&树状数组)
- HDoj-1556-Color the ball-树状数组
- hdoj 1556 Color the ball 【树状数组】
- hdoj 1556 Color the ball(树状数组)
- HDOJ Color the ball 1556【树状数组】
- HDOJ 题目1556Color the ball(树状数组)
- hdoj 1556 Color the ball(线段树||树状数组)
- HDOJ 1556 Color the ball(树状数组 & 线段树)
- HDOJ 1556 Color the ball(树状数组)
- HDOJ 1556 Color the ball(树状数组模板)
- HDOJ/HDU 1556 Color the ball(树状数组)
- hdoj-1556Color 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 树状数组
- 爬取豆瓣网电影信息
- hdoj 绝对值排序
- 【HTML5+css3】学习笔记之实体、元数据和全局属性
- iOS 自动布局 Masonry
- Rightmost Digit
- hdoj--1556--Color the ball(模拟&&树状数组)
- 【FastDev4Android框架开发】实例解析之SwipeRefreshLayout+RecyclerView+CardView(三十五)
- Android主线程向子线程中发送信息
- POJ1159 DPorLCS妙用
- 二叉树的递归遍历和非递归遍历
- 杭电oj 1008
- Linux下查看文件和文件夹大小
- 破损的键盘(uva 11988)
- Java BigDecimal和double