hdu 1556 Color the ball
2012-08-27 17:29
405 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1556
Total Submission(s): 4343 Accepted Submission(s): 2325
[align=left]Problem Description[/align]
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
[align=left]Input[/align]
每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。
[align=left]Output[/align]
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
[align=left]Sample Input[/align]
3 1 1 2 2 3 3 3 1 1 1 2 1 3 0
[align=left]Sample Output[/align]
1 1 1 3 2 1
[align=left]Author[/align]
8600
[align=left]Source[/align]
HDU 2006-12 Programming Contest
[align=left]Recommend[/align]
LL
初学线段树,,,照着写,弱爆了!!!!!!!!
View Code
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4343 Accepted Submission(s): 2325
[align=left]Problem Description[/align]
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
[align=left]Input[/align]
每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。
[align=left]Output[/align]
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
[align=left]Sample Input[/align]
3 1 1 2 2 3 3 3 1 1 1 2 1 3 0
[align=left]Sample Output[/align]
1 1 1 3 2 1
[align=left]Author[/align]
8600
[align=left]Source[/align]
HDU 2006-12 Programming Contest
[align=left]Recommend[/align]
LL
初学线段树,,,照着写,弱爆了!!!!!!!!
View Code
#include<stdio.h> #include<string.h> int a[100001],b[1000001],c[1000001]; int main() { int n,x,y,i; while(~scanf("%d",&n),n) {int f=0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(i=0;i<n;i++) { scanf("%d%d",&x,&y); a[x]++;//开始点等于x的个数 b[y]++;//终点为y的个数 } c =b ;//c[i]为要求的 for(i=n-1;i>=0;i--) c[i]=b[i]+c[i+1]-a[i+1]; /* c[6]=b[6]+c[7]-a[7] 6被涂的次数等于超过终点超过6且起始点不超过六加上b[6]的和 */ for(i=1;i<=n;i++) { if(f) printf(" "); printf("%d",c[i]); f=1; } printf("\n"); } }
相关文章推荐
- 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 (线段树)
- HDU 1556 Color the ball【线段树区间更新,一次查询+数组模拟】
- HDU 1556 Color the ball(树状数组)(填坑)
- HDU 1556-Color the ball(树状数组-区间修改 单点查询)
- HDU 1556 Color the ball