poj 2182
来源:互联网 发布:java常用算法有哪些 编辑:程序博客网 时间:2024/04/30 15:07
题目
和poj 2828差不多的意思
#include<iostream>#include<algorithm>#include<cstdio>using namespace std;#define maxn 8010#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1struct Tree{ int l,r,num;}tree[maxn<<2];int p[maxn],ans[maxn];void build(int l,int r,int rt){ tree[rt].l=l; tree[rt].r=r; tree[rt].num=r-l+1; if(tree[rt].l==tree[rt].r) return ; int m=(l+r)>>1; build(lson); build(rson);}int query(int pos,int rt){ int l,r; l=tree[rt].l; r=tree[rt].r; tree[rt].num--; if(l==r) return l; if(pos<=tree[rt<<1].num) return query(pos,rt<<1); else{ return query(pos-tree[rt<<1].num,rt<<1|1); }}int main(){ int i,n; while(~scanf("%d",&n)){ build(1,n,1); p[1]=0; for(i=2;i<=n;i++){ scanf("%d",&p[i]); } for(i=n;i>=1;i--){ ans[i]=query(p[i]+1,1); } for(i=1;i<=n;i++){ printf("%d\n",ans[i]); } return 0; } return 0;}
- POJ 2182
- poj 2182
- poj 2182
- poj 2182
- poj 2182
- poj 2182
- poj 2182
- poj 2182
- poj 2182
- poj 2182
- poj 2182
- poj 2182
- poj 2182
- POJ 2182 :Lost Cows
- poj 2182 Lost Cows
- poj 2182 Lost Cows
- poj 2182 Lost Cows
- POJ 2182 Lost Cows
- Java 虚拟机学习 - 对象访问的定位方式
- uva10004 Bicoloring 黑白染色问题,DFS
- 高效算法设计专项:UVa 10691
- 排序算法练习——代码汇总
- 窗体接收拖入数据与拖动窗体内容移动
- poj 2182
- Oracle学习(14)---Oracle的自动工作负载库(AWR)和自动诊断工具(ADDM)
- C++程序设计语言学习笔记(三)
- 在JSP里使用CKEditor和CKFinder
- 白话MSDN:从普通DLL中导出C++类(1) – dllexport和dllimport的使用方法(中英对照、附注解)
- Makefile常用函数总结
- <%! 定义 %>与 <% 定义 %>区别
- CKEditor/CKFinder升级心得
- 【C++自我精讲】基础系列三 重载