poj 2352 Stars (树状数组)
来源:互联网 发布:js获取class元素 编辑:程序博客网 时间:2024/05/20 22:26
题目分析:一个数组中,求某个元素左边小于等于它的数的个数,记为level, ans[level]++,按level 从0到输出他们出现次数,
代码:
#include<iostream>#include<cstdio>#include<memory.h>using namespace std;const int MAX=100000;int ans[MAX],tree[MAX],n;int LowBit(int x){return x&(-x);}int GetSum(int x){int temp=0;for(int i=x;i>=1;i-=LowBit(i))temp+=tree[i];return temp;}void UpDate(int x,int c){for(int i=x;i<=MAX;i+=LowBit(i)) tree[i]+=c;}int main(){while(scanf("%d",&n)!=EOF){int x,y;memset(tree,0,sizeof(tree));memset(ans,0,sizeof(ans));for(int i=1;i<=n;i++){scanf("%d %d",&x,&y); ans[GetSum(x+1)]++;//因为0<=x<=32000,注意x==0,否则死循环UpDate(x+1,1);}for(int i=0;i<n;i++)printf("%d\n",ans[i]);}system("pause");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 (树状数组!!)
- Stars (poj 2352 树状数组)
- POJ 2352 Stars(树状数组)
- POJ---2352-Stars(树状数组)
- POJ 2352 Stars (树状数组)
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars(树状数组)
- POJ 2352 Stars (树状数组)
- hash_map
- thinkphp登陆
- 初学Android,使用自定义的XML资源(十八)
- oracle 千万级别同一数据库 不同scheme下的数据导入
- 【hdu】 What Are You Talking About (水题 STL)
- poj 2352 Stars (树状数组)
- 漂浮的移动广告 碰到边框改变移动路径
- 图像缩放函数
- J2SE基础夯实系列之静态导入,foreach循环,可变参数
- SharePoint2010 Feature功能开发——为SharePoint的ECB菜单(列表项或文档的操作菜单项)添加自定义菜单栏项目
- 三大框架SSH(struts2+spring+hibernate)整合时相关配置文件的模板
- Permission denied: make_sock: could not bind to address处理
- 我不知道怎么加图片了···
- myeclipse常用快捷键