POJ 2352 Stars(树状数组)
来源:互联网 发布:花生日记app淘宝 编辑:程序博客网 时间:2024/06/16 05:02
这道题的意思就是在笛卡尔坐标系上给你n个点,每个点有等级,等级表示的是在这个点的左下有多少个点。让你按顺序把所有的等级的个数输出。
思路 :
这题的输入是按照从·左向右从上向下的顺序的,所以直接用二维数组就好了
AC代码:
/* ***********************************************Author :yzkAcceptedCreated Time :2016/3/4 11:03:26TASK :ggfly.cppLANG :C++************************************************ */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#include <stack>using namespace std;typedef __int64 ll;const int maxn=150010;int n,a[maxn],lowbit[maxn],ans[maxn];void add(int k){while(k<maxn){a[k]++;k+=lowbit[k];}}int sum(int k){ll s=0;while(k>0){s+=a[k];k-=lowbit[k];}return s;}int main(){for(int i=1;i<=maxn;i++)lowbit[i]=i&(-i); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while(~scanf("%d",&n)){int x,y;memset(a,0,sizeof(a));for(int i=0;i<n;i++){scanf("%d%d",&x,&y);x++,y++;ans[sum(x)]++;add(x);}for(int i=0;i<n;i++){printf("%d\n",ans[i]);}} return 0;}
0 0
- 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 Stars 树状数组
- poj 2352 Stars 树状数组
- poj 2352 Stars 树状数组
- POJ:2352 Stars(树状数组)
- [树状数组]POJ 2352 Stars
- POJ-2352-Stars 树状数组
- Stars - POJ 2352 树状数组
- poj 2352 Stars 树状数组
- poj 2352 Stars (树状数组)
- POJ 2352 Stars【树状数组】
- 1030. 完美数列(25)
- matlab strcmp
- 向量集
- 加载storyboard,并设置根控制器
- 华为EMUI4.0 基于android 6.0的bug
- POJ 2352 Stars(树状数组)
- 进程控制
- Android消息机制不完全解析(上) .
- Android数据存储方式之——文件存储
- 一个单机棋盘式半即时解谜RPG的开发与反思、1
- 将DHT11移植到Linux系统上
- 写给自己的鸡汤
- HDU FatMouse' Trade
- cocos2dx 事件侦听