poj 2182 lost cows 树状数组,二分
2012-01-10 12:56
363 查看
线段树做法
/article/5032239.html
从后往前操作
View Code
/article/5032239.html
从后往前操作
View Code
#include<cstdio> #include<cstring> const int maxn = 80001; int a[maxn],c[maxn],ans[maxn],n; int lowbit(int x){ return x&-x; } void update(int x,int d){ for(;x<maxn;x+=lowbit(x)) c[x]+=d; } int sum(int x){ int ans=0; for(;x>0;x-=lowbit(x)) ans+=c[x]; return ans; } int bin(int num){ int l=1,r=n,mid,tmp,best; while(l<=r){ mid=(l+r)>>1; tmp=sum(mid); if(tmp>=num){ best=mid; r=mid-1; } else l=mid+1; } return best; } int main(){ int i,j; while(~scanf("%d",&n)){ memset(c,0,sizeof(c)); a[1]=0;update(1,1); for(i=2;i<=n;i++){ scanf("%d",&a[i]); update(i,1); } for(i=n;i>=1;i--){ int pos=bin(a[i]+1); ans[i]=pos; update(pos,-1); } for(i=1;i<=n;i++) printf("%d\n",ans[i]); } }
相关文章推荐
- POJ 2104 K-th Number【整体二分 + 树状数组】
- POJ 2104 K-th Number【整体二分 + 树状数组】
- POJ-2985(树状数组 + 并查集 + 二分)
- POJ 2892 Tunnel Warfare (树状数组+二分)
- POJ 2892 Tunnel Warfare || HDU 1540(树状数组+二分 || 线段树的单点更新+区间查询)
- POJ 题目2182 Lost Cows(树状数组+二分)
- POJ 2892 Tunnel Warfare(树状数组+二分)
- POJ 3110 Jenny's First Exam (二分 + 树状数组 + 贪心 + 预处理年份)
- POJ - 2886 Who Gets the Most Candies? 树状数组 + 二分 + 反素数
- POJ 2182 Lost Cows(树状数组+二分)
- poj 2892 Tunnel Warfare(树状数组+二分)
- POJ 2886 Who Gets the Most Candies?(树状数组+二分)
- poj 2892 树状数组 二分
- POJ-2182 Lost Cows (二分 + 树状数组 或者平衡树)
- 【poj 2104】K-th Number【整体二分+树状数组】
- poj 2892 Tunnel Warfare(树状数组+二分)
- 【POJ 2892】 Tunnel Warfare(树状数组+二分)
- poj 2886 Who Gets the Most Candies? (树状数组+二分+反素数)
- POJ-2892(树状数组 + 二分)
- POJ 2182 Lost Cows (树状数组+二分 / 线段树 / 枚举)