【树状数组】 poj2352 Stars
2012-08-19 10:57
330 查看
Stars
题目:http://poj.org/problem?id=2352
题意:在一个二维数组中统计某个等级星星的个数,星星的等级为不比此星星高且不在它右边范围内的星星个数。
题解:因为输入的数据已经排序,只要一边接收输入一边计算等级即可。
代码:
题目:http://poj.org/problem?id=2352
题意:在一个二维数组中统计某个等级星星的个数,星星的等级为不比此星星高且不在它右边范围内的星星个数。
题解:因为输入的数据已经排序,只要一边接收输入一边计算等级即可。
代码:
#include<cstdio> #include<cstring> using namespace std; int a[15005],c[32010]; #define lowbit(x) ((x)&(-(x))) void update(int pos,int value) //更新pos的值 { int x=pos; for(;x<=32005;x+=lowbit(x)) c[x]+=value; } int getsum(int pos)//求1到pos位置的和 { int x=pos,sum=0; for(;x>0;x-=lowbit(x)) sum+=c[x]; return sum; } int main() { int x,y,n; for(;~scanf("%d",&n);) { memset(c,0,sizeof(c)); memset(a,0,sizeof(a)); for(int i=0;i<n;++i) { scanf("%d%d",&x,&y); a[getsum(x+1)]++; update(x+1,1); } for(int i=0;i<n;++i) printf("%d\n",a[i]); } return 0; }来源:http://blog.csdn.net/ACM_Ted
相关文章推荐
- poj2352 Stars(树状数组)
- poj 2352 Stars(树状数组)
- poj 2352 Stars (树状数组)
- POJ 2481 Cows && POJ 2352 Stars(树状数组妙用)
- poj2352——Stars(树状数组)
- POJ 2352 Stars(树状数组)
- poj 2352 Stars (树状数组 +1 的运用)
- POJ-2352(Stars)树状数组解法
- 【二维偏序】【树状数组】【权值分块】【分块】poj2352 Stars
- poj 2352 Stars(树状数组)
- 【原】 POJ 2352 Stars 树状数组 解题报告
- poj 2352 stars (树状数组)
- POJ---2352-Stars(树状数组)
- poj 2352 && hdu 1541 Stars (树状数组)
- poj 2352 OR hdu 1541 Stars(数据结构:树状数组)
- POJ 2352 Stars + HDU 1556 Color the ball(树状数组单点更新及伪区间更新)
- poj 2352 Stars(树状数组)
- poj 2352 Stars(树状数组)
- POJ 2352 Stars(树状数组)
- 【树状数组】尝试 POJ2352-Stars