POJ 2352 Stars

解题思路:线段数组求解小于当前点x坐标点的个数

代码
   
     
#include < iostream >
using namespace std;
#define lowbit(k) (k&(k^(k-1)))
int main()
{
int i,n,t,s,maxX,x[ 15000 ],y[ 15000 ],m[ 32002 ] = { 0 },level[ 15000 ] = { 0 };
scanf(
" %d " , & n);
for (maxX = i = 0 ;i < n;i ++ ){scanf( " %d %d " ,x + i,y + i); if (x[i] > maxX)maxX = x[i];}
for (i = 0 ;i < n;i ++ )
{
s
= 0 ,t = x[i] + 1 ;
while (t > 0 )s += m[t],t -= lowbit(t);
level[s]
++ ;
t
= x[i] + 1 ;
while (t <= maxX + 1 )m[t] ++ ,t += lowbit(t);
}
for (i = 0 ;i < n;i ++ )printf( " %d\n " , level[i]);
return 0 ;
}

 

你可能感兴趣的:(tar)