poj 2182 lost cows 树状数组,二分
来源:互联网 发布:博易大师软件 编辑:程序博客网 时间:2024/05/18 00:15
线段树做法
http://www.cnblogs.com/wuyiqi/archive/2011/12/21/2295391.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 2182 lost cows 树状数组,二分
- poj 2182 Lost Cows--树状数组+二分
- POJ 题目2182 Lost Cows(树状数组+二分)
- Poj 2182-Lost Cows(Treap||树状数组+二分答案)
- POJ 2182 Lost Cows(树状数组+二分)
- POJ 2182 Lost Cows (树状数组+二分 / 线段树 / 枚举)
- POJ 2182 Lost Cows 树状数组
- poj 2182 Lost Cows(树状数组)
- poj 2182 Lost Cows 树状数组
- poj 2182 Lost Cows 树状数组
- [POJ 2182] Lost Cows · 树状数组
- poj 2182 Lost Cows 树状数组
- POJ 2182 Lost Cows(树状数组)
- POJ 2182 Lost Cows树状数组
- POJ 2182 Lost Cows树状数组 *
- 【树状数组--思维】poj 2182 Lost Cows
- POJ 2182 Lost Cows(树状数组)
- POJ 2182——Lost Cows(树状数组+二分查找 nlgnlgn)
- hdu 2546 01背包
- poj 2486 apple tree 树形DP 不懂的一定把你讲懂
- HashMap源码分析(基于JDK1.6)
- poj 2777 count color
- hdu 3577 线段树,成段更新 好题 查询区间的最大覆盖次数
- poj 2182 lost cows 树状数组,二分
- hdu 4031 attack 树状数组 线段树 两种做法
- hdu 3460 Ancient Printer
- hdu 4107 Gangster 线段树 成段更新
- hdu 2227 Find the nondecreasing subsequences 树状数组+简单DP
- poj 3667 Hotel 区间合并
- hdu 2757 广搜+优先队列
- hdu 1542 线段树 求面积并
- hdu 1225 求覆盖至少两次的区域的面积并