POJ 2352 树状数组
2012-04-16 17:02
357 查看
这是一道YY题= =...
确实.. 做这题我就是YY出来的。一交没想到1Y了~ 哈哈哈~ 笑死我了~
树状数组再练一道就罢手!
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int c[15555],n,lev[15555];
struct point
{
int x,y,pos;
}p[15555];
bool cmp1( point a,point b )
{
if( a.x==b.x )
return a.y<b.y;
return a.x<b.x;
}
bool cmp2( point a,point b )
{
if( a.y==b.y )
return a.x<b.x;
return a.y<b.y;
}
int lowbit( int x ){ return x&-x; }
int sum( int x )
{
int rec=0;
while( x )
{
rec+=c[x];
x-=lowbit(x);
}
return rec;
}
void add( int x,int v )
{
while( x<=n )
{
c[x]+=v;
x+=lowbit(x);
}
}
int main()
{
while( scanf("%d",&n)!=EOF )
{
memset( c,0,sizeof(c) );
memset(lev,0,sizeof(lev));
for( int i=0;i<n;i++ )
scanf( "%d%d",&p[i].x,&p[i].y );
sort( p,p+n,cmp1 );
for( int i=0;i<n;i++ )
p[i].pos=i+1;
sort( p,p+n,cmp2 );
for( int i=0;i<n;i++ )
{
//printf( "pos:%d\n",p[i].pos );
lev[sum(p[i].pos)]++;
add( p[i].pos,1 );
}
for( int i=0;i<n;i++ )
printf( "%d\n",lev[i] );
}
return 0;
}
确实.. 做这题我就是YY出来的。一交没想到1Y了~ 哈哈哈~ 笑死我了~
树状数组再练一道就罢手!
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int c[15555],n,lev[15555];
struct point
{
int x,y,pos;
}p[15555];
bool cmp1( point a,point b )
{
if( a.x==b.x )
return a.y<b.y;
return a.x<b.x;
}
bool cmp2( point a,point b )
{
if( a.y==b.y )
return a.x<b.x;
return a.y<b.y;
}
int lowbit( int x ){ return x&-x; }
int sum( int x )
{
int rec=0;
while( x )
{
rec+=c[x];
x-=lowbit(x);
}
return rec;
}
void add( int x,int v )
{
while( x<=n )
{
c[x]+=v;
x+=lowbit(x);
}
}
int main()
{
while( scanf("%d",&n)!=EOF )
{
memset( c,0,sizeof(c) );
memset(lev,0,sizeof(lev));
for( int i=0;i<n;i++ )
scanf( "%d%d",&p[i].x,&p[i].y );
sort( p,p+n,cmp1 );
for( int i=0;i<n;i++ )
p[i].pos=i+1;
sort( p,p+n,cmp2 );
for( int i=0;i<n;i++ )
{
//printf( "pos:%d\n",p[i].pos );
lev[sum(p[i].pos)]++;
add( p[i].pos,1 );
}
for( int i=0;i<n;i++ )
printf( "%d\n",lev[i] );
}
return 0;
}
相关文章推荐
- poj 2352 树状数组
- POJ 2352 Stars 树状数组
- poj 2352 树状数组(星星的级别)
- poj 2352 入门树状数组
- POJ_2352_树状数组
- poj 2352 hdu 2642 hdu 1556 poj 2155 树状数组
- 树状数组 poj 2352
- poj 2352 Stars 树状数组
- Stars (poj 2352 树状数组)
- POJ 2352 Stars 初学树状数组
- POJ 2352 stars 树状数组
- POJ 2352 Stars 树状数组
- poj 2352 Stars 树状数组
- poj_2352树状数组
- POJ 2352 树状数组
- poj 2352 树状数组
- poj 2352 Stars(线段树||树状数组)
- POJ 2352 Star (树状数组)
- poj 2352 树状数组
- POJ2352 Stars 树状数组简单应用