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;
}

本文介绍如何使用树状数组解决星图中星等分布的问题。通过输入星图坐标,计算并输出每颗星的等级数量,实现对星图数据的高效处理。
715

被折叠的 条评论
为什么被折叠?



