hdu1556 Color the ball
来源:互联网 发布:破解密码的软件 编辑:程序博客网 时间:2024/05/21 09:15
原题链接:click here
这以题既可以用树状数组来做,也可以用线段树来做,可惜我还没掌握线段树,等以后掌握了再补充下。
代码如下:
#include<stdio.h>
int n;
int tree[100005];
int lowbit(int i)
{
return i&(-i);
}
void update(int i,int j)
{
while(i<=n)
{
tree[i]+=j;
i+=lowbit(i);
}
}
int sum(int k)
{
int sum=0;
while(k>0)
{
sum+=tree[k];
k-=lowbit(k);
}
return sum;
}
int main()
{
int a,b,i,k;
while(scanf("%d",&n)!=EOF&&n!=0)
{
k=n;
memset(tree,0,sizeof(tree));
while(k--)
{
scanf("%d%d",&a,&b);
update(a,1);//树状数组从a向后更新(每次更新都加上1)
update(b+1,-1);//从b+1开始向后更新,每次更新都减去1,因为题目是从a到b的更新,多加的要减掉
}
for(i=1;i<=n;i++)
{
printf("%d",sum(i));
if(i!=n)
printf(" ");
else
printf("\n");
}
}
return 0;
}
- hdu1556 color the ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- HDU1556 Color the ball
- hdu1556 Color the ball
- hdu1556--Color the ball
- Color the ball HDU1556
- HDU1556 Color the ball
- hdu1556 Color the ball
- HDU1556-----Color the ball
- hdu1556 Color the Ball
- HDU1556-color the ball
- HDU1556 Color the ball
- hdu1556 Color the ball
- Color the ball||HDU1556
- HDU1556 Color the ball
- HDU1556 Color the ball(线段树)
- C# 数据库操作通用代码段
- js 判断svg插件(adobe viewer)
- ecshop购物车重登陆不丢失数据
- Android应用开发学习笔记之相对布局
- BOM相关性维护
- hdu1556 Color the ball
- PB学习笔记(一)
- android中phonegap下js调用java代码 progressbar显示的控制
- 武器库
- mysql 编码方式设置
- SecureCRT
- 学习线段树的一点心得
- 异美旅游
- 非线性曲线拟合函数 lsqcurvefit 最小二乘