poj 2352 Stars 树状数组
【摘要】
题目链接
Description
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a sta...
Description
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the levels of the stars.………………
树状数组,简单题,我刚刚开始学的时候就a了,不多说什么了,直接贴代码。
#include<stdio.h>
#include<string.h>
int a[32002];
int level[15002];
int lowbit(int x)
{
return x&(-x);
}
void insert(int x)
{
while(x<32002)
{
a[x]++;
x += lowbit(x);
}
}
int sum(int x)
{
int s=0;
while(x)
{
s += a[x];
x -= lowbit(x);
}
return s;
}
int main()
{
int n, i, x, y;
scanf("%d",&n);
memset(a,0,sizeof(level));
memset(level,0,sizeof(level));
for(i = 0; i < n; i++)
{
scanf("%d%d",&x,&y);
x++;
level[sum(x)]++;
insert(x);
}
for(i= 0; i < n; i++)
printf("%d\n",level[i]);
return 0;
}
文章来源: xindoo.blog.csdn.net,作者:xindoo,版权归原作者所有,如需转载,请联系作者。
原文链接:xindoo.blog.csdn.net/article/details/8763419
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)