poj 2182||hdu 2711
来源:互联网 发布:市场数据分析报告范文 编辑:程序博客网 时间:2024/06/07 12:06
题目链接
树状数组+二分
poj2182 AC hdu2711 WA 有时间在研究吧
#include <cstdio>#include <cstring>using namespace std;#define maxn 8005int arr[maxn],a[maxn],s[maxn];int lowbit(int x){ return x&(-x);}void update(int x,int n){ while(x<=n) { arr[x]++; x+=lowbit(x); }}int getsum(int x){ int ans=0; while(x>0) { ans+=arr[x]; x-=lowbit(x); } return ans;}int search(int x,int n){ int left=1,right=n,mid,temp; while(left<right) { mid=(left+right)/2; temp=mid-getsum(mid); if(temp<x) left=mid+1; else right=mid; } return left;}int main(){ int n,i,j,k; while(scanf("%d",&n)!=EOF) { for(i=2;i<=n;i++) scanf("%d",&a[i]); for(i=n;i>=1;i--) { k=search(a[i]+1,n); update(k,n); s[i]=k; } for(i=1;i<=n;i++) printf("%d\n",s[i]); } return 0;}
大神插空 都AC
#include <cstdio>using namespace std;#define maxn 8005int cow[maxn],d[maxn];int main(){ int i,head,t,n,num,current,m; while(scanf("%d",&n)!=EOF) { head=1; cow[head]=0; for(i=2;i<=n;i++) { scanf("%d",&num); if(num) { current=head; while(--num) current=cow[current]; t=cow[current]; cow[current]=i; cow[i]=t; } else { cow[i]=head; head=i; } } m=0; for(i=head;i;i=cow[i]) d[i]=++m; for(i=1;i<=n;i++) printf("%d\n",d[i]); } return 0;}
算法
- poj 2182||hdu 2711
- poj 2182 || hdu 2711 Lost Cows
- hdu 2732&&poj 2711 (最大流)
- poj hdu Tunnel Warfare
- hdu 1700 poj 2954
- poj 1177 && hdu 1828
- poj 3990 hdu 3694
- POJ 1466/HDU 1068
- hdu,poj 分类
- POJ 2238 && HDU 4294
- hdu 4009 && POJ 3164
- HDU 1043、POJ 1077
- 刷poj、hdu有感
- hdu 1540 && poj 2892
- hdu 1542 &&poj 1151
- hdu 1325 poj 1308
- poj 1503 hdu 1002
- POJ 1904 HDU 4685
- 画UML类图
- firefly框架分析之netconnect package(四)
- JS动态操作表格
- JUnit最佳实践
- 进程间通讯方法总结
- poj 2182||hdu 2711
- Unity里面应尽量避免使用foreach
- UVAlive 6151 Beehives 解题报告
- hdu 1392求凸包(即求包围所有树的最短距离)
- 多线程题 3个线程各打印一种字母,按顺序打印若干次ABC 的2种实现
- Google V8 JavaScript应用测试实例
- SystemTap----初始化和遍历数组
- 15道IQ题,看你能答出几道。
- hadoop 准备之linux相关