HDU 1556 数组巧用
来源:互联网 发布:深圳网络教育机构 编辑:程序博客网 时间:2024/04/28 11:25
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14630 Accepted Submission(s): 7307
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
类似于打括号的方式解题,先用二维数组arry[maxn][2] 分别打左括号和右括号,最后计算某一个位置涂了多少次颜色的时候,只需要用它左边左括号的数量减去右括号的数量即可,这个过程可以再用一个数组简单实现。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn = 100005 ;int arry[maxn][2] ;int main(){ int n; while(~scanf("%d",&n),n){ memset(arry,0,sizeof(arry)); for(int i=0;i<n;i++){ int a,b ; scanf("%d %d",&a,&b); arry[a][0]++ ; ///左括号 arry[b+1][1]++ ; ///右括号 } int ans[maxn] ; memset(ans,0,sizeof(ans)); ans[0]=0; for(int i=1;i<=n;i++){ if(arry[i][0]+arry[i][1]!=0){ ans[i]=ans[i-1]+arry[i][0]-arry[i][1] ; ///计算该位置涂了多少次 }else{ ans[i]=ans[i-1] ; } } printf("%d",ans[1]); for(int i=2;i<=n;i++){ printf(" %d",ans[i]); } printf("\n"); }}
0 0
- HDU 1556 数组巧用
- 数组巧用——HDU 4970
- hdu 1556 树状数组
- hdu (1556 树状数组)
- HDU 1556 树状数组
- HDU 1556树状数组求解
- HDU 1556(树状数组)
- 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 树状数组(插线问点)
- HDU 1556 Color the ball(树状数组)
- Oracle12c中SQL优化(SQL TUNING)新特性之SQL计划指令
- 【bzoj1305】[CQOI2009]dance跳舞 最大流
- Codeforces Round #345 (Div. 2) (D. Image Preview(二分))
- NVIDIA Jetson TK1学习与开发(五):helloworld的C版本与C++版本
- 时间复杂度
- HDU 1556 数组巧用
- 声明一个指向含有10个元素的数组的指针,其中每个元素是一个函数指针,该函数的返回值是int,参数是int*,正确的是()
- Problem G: C语言习题 输出月份
- windows客户端开发--为你的客户端增加消息提示音
- Unity3D:unity与Android相互传递消息 & unity与ios相互传递消息
- Boost库学习
- 维护IOS项目时遇到的一些问题
- JAVA调用条码打印机打印二维码
- spring aop