hdu 1556 Color the ball
来源:互联网 发布:父亲礼物 知乎 编辑:程序博客网 时间:2024/05/22 02:14
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 15079 Accepted Submission(s): 7507
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
比较简单,一边比较一遍输出就好;
直接上代码;
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int a[100001];int b[100001];int main(){ int N; while(scanf("%d",&N)!=EOF&&N) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(int i=1;i<=N;++i) { scanf("%d %d",&a[i],&b[i]); } sort(a+1,a+N+1); sort(b+1,b+N+1); int ai=1,bi=1; int ans=0; for(int i=1;i<=N;++i) { while(ai<=N&&i>=a[ai]) { ++ans; ++ai; } if(i==N) printf("%d",ans); else printf("%d ",ans); while(bi<=N&&i>=b[bi]) { --ans; ++bi; } } printf("\n"); } return 0;}
0 0
- hdu 1556 color the ball
- hdu 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
- 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
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- hibernate ORM映射:双向多对一
- spring security:自定义认证成功处理器
- Ubuntu下通过PPA方式安装Java 8和自动配置环境变量
- LeetCode *** 22. Generate Parentheses
- UVA 11722
- hdu 1556 Color the ball
- 朴素的模式匹配算法
- UI布局学习
- 算法_动态规划_乘法表问题
- 装饰者模式
- Windows 服务应用程序
- PorterDuffXfermode自定义View实现圆角图片
- hiho一下 第十九周 RMQ问题再临-线段树
- android常见漏洞