POJ 2352 Stars 树状素组
来源:互联网 发布:阿里云国际绑定paypal 编辑:程序博客网 时间:2024/05/18 00:12
题意:给定若干个点(星星),每个点的评级标准是既不在它右边,也不在它上边的点的个数,求每个等级所含有的星星个数。
做法:因为输入时,坐标已经按y,x递增排序,所以可以更加x坐标统计某一时刻0-x坐标范围内所含有的点的个数。因为输入限制,可以确定的是,每次使用sum函数得到的值一定都是符合题意的。
#include<cstdio>#include<iostream>#include<cstring>#define LMT 32005#define lowbit(x) x&(-x)using namespace std;int num[LMT],n,lev[15005];void init(void){ memset(num,0,sizeof(num)); memset(lev,0,sizeof(lev));}void update(int x,int ope){ while(x<LMT) { num[x]+=ope; x+=lowbit(x); }}int sum(int x){ int ret=0; while(x>0) { ret+=num[x]; x-=lowbit(x); } return ret;}int main(void){ int x,y,tem; while(~scanf("%d",&n)) { init(); for(int i=1;i<=n;i++) { scanf("%d%d",&x,&y); x++; tem=sum(x); lev[tem]++; update(x,1); } for(int i=0;i<n;i++)printf("%d\n",lev[i]); } return 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
- POJ-2352-Stars 树状数组
- Stars - POJ 2352 树状数组
- poj 2352 Stars 树状数组
- poj 2352 Stars (树状数组)
- 使用GDI+进行开发的一些问题(1)
- XML学习之Xml Schema:八、派生复杂类型--限制
- 项目KT总结
- 算法导论---红黑树删除详解
- android:shape的使用
- POJ 2352 Stars 树状素组
- Matlab中执行Linux命令
- How tomcat work读书笔记 chapter2 a simple servlet
- 一个领导者选举算法
- emacs学习(三)
- whoami
- 树莓派(raspberry pi)学习17:我的树莓派在哪? --找回丢失的树莓派
- Chapter11-"windows线程池" 之 内核对象触发调用回调函数
- string类 成员函数简单示例(1)