Color the ball
来源:互联网 发布:辐射4萌妹捏脸数据 编辑:程序博客网 时间:2024/06/05 22:34
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19849 Accepted Submission(s): 9897
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
代码写出来了,但是一开始不知道原理是什么,然后突然看到了另一份代码就懂了。
#include<stdio.h> #include<string.h> int s[100100]; int main(){ int n; while(~scanf("%d",&n)&&n){ int i,j,k; int x,y; memset(s,0,sizeof(s)); for(i=1;i<=n;i++){ scanf("%d %d",&x,&y); s[x]++; s[y+1]--; } int sum=0; for(i=1;i<n;i++){ sum+=s[i]; printf("%d ",sum); } sum+=s[i]; printf("%d\n",sum); } return 0; }
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;const int Maxn=100000;int sum[1000005],n;int lowbit(int x){ return x&(-x);}void updata(int x,int cnt){ while(x<=Maxn){ sum[x]+=cnt; x+=lowbit(x); }}int getSum(int x){ int s=0; while(x>0){ s+=sum[x]; x-=lowbit(x); } return s;}int main(){ // freopen("in.txt","r",stdin); while(scanf("%d",&n)&&n){ memset(sum,0,sizeof(sum)); for(int l,r,i=1;i<=n;i++){ scanf("%d%d",&l,&r); updata(l,1); updata(r+1,-1); } for(int i=1;i<n;i++) printf("%d ",getSum(i)); printf("%d\n",getSum(n)); }}
阅读全文
0 0
- hdu1556 color the ball
- HDOJ Color the ball
- Color the ball
- Color the Ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- hdu_1556 Color the ball
- hdu1556 Color the ball
- Color the ball----HDOJ1556
- HDU1556 Color the ball
- Color the ball
- Color the ball
- hdu1556 Color the ball
- hdu1556--Color the ball
- HDU_1556 Color the ball
- Color the ball HDU1556
- HDU1556 Color the ball
- Color the ball
- 对titanic.csv数据进行预测生死
- java.lang.IllegalStateException: ScrollView can host only one direct child
- 列表笔记
- 使用Redux和ngrx构建更好的Angular2应用(二)
- iOS的进阶之路
- Color the ball
- xcode调试技巧
- velocity例子
- 高德地图小区边界获取(2017.05)
- 数据结构说明
- ant design (antd) Form.Item Objects are not valid as a React child
- 需求分析重要的思维方法,1张流程图学会“结果逆推”!
- 使用Hive实现时间拉链功能
- Doxygen详细介绍