xindoo is
always here

# 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 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.………………

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


• QQ咨询
• 回顶