POJ 2352 Stars
2017-05-07 19:24
399 查看
http://poj.org/problem?id=2352
题意:
给出每个星星的x、y坐标,计算每颗星星左方和正下方的星星个数。
思路:
由于星星是根据y坐标递增的基础上再根据x坐标递增的顺序给出,所以我们只需要考虑横坐标上的星星情况,至于正下方的星星个数,我们只需要记录一下最后加上即可。
题意:
给出每个星星的x、y坐标,计算每颗星星左方和正下方的星星个数。
思路:
由于星星是根据y坐标递增的基础上再根据x坐标递增的顺序给出,所以我们只需要考虑横坐标上的星星情况,至于正下方的星星个数,我们只需要记录一下最后加上即可。
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #include<queue> #include<cmath> #include<map> #include<stack> using namespace std; const int maxn=32000+5; int n; int c[maxn]; int ans[maxn]; int num[maxn]; int lowbit(int x) { return x&-x; } int sum(int x) { int ret=0; while(x>0) { ret+=c[x]; x-=lowbit(x); } return ret; } void add(int x,int d) { while(x<=maxn) { c[x]+=d; x+=lowbit(x); } } int main() { //freopen("D:\\input.txt","r",stdin); scanf("%d",&n); for(int i=0;i<n;i++) { int x,y; scanf("%d%d",&x,&y); x++; //注意这儿需要+1,因为x为0也是有可能的 add(x,1); int p=sum(x-1); p+=num[x]; //加上正下方的星星个数 ans[p]++; num[x]++; } for(int i=0;i<n;i++) printf("%d\n",ans[i]); return 0; }
相关文章推荐
- 树状数组 POJ 2352 HDU 1541 Stars
- POJ 2352 Stars
- poj 2352 Stars (树状数组 +1 的运用)
- 【树状数组第一弹】poj 2352——Stars
- POJ 2352 Stars 线段树
- poj 2352 Stars
- POJ 2352 Stars(简单树状数组)
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars (树状数组)
- POJ 2352 Stars (树状数组)
- poj 2352 Stars(简单树状数组)此题也可以用线段树来做
- POJ 2352 HDU1541 Stars(树状数组)
- POJ 2352 Stars
- POJ 2352 Stars 题解
- POJ2352 Stars
- POJ 2352 Stars
- POJ 2352 Stars
- POJ 2352 Stars 树状数组
- POJ 2352 Stars
- poj 2352 Stars (树状数组)