二叉排序树--cf675d Tree construction
来源:互联网 发布:百川环评工程师软件 编辑:程序博客网 时间:2024/06/05 15:20
给定一个数列,依次建立二叉排序树,求除根结点外,每个结点的父亲。
//二叉排序树所有根结点都比他左儿子大,都比他右儿子小
//最后的树在地上的映射就是排好序的,所以一个点的父亲要么是排序后,在他左边的,要么事在他右边
//并且应该是两个中添加时间最晚的
#include <iostream>
#include <cstdio>
#include <set>
#include <iterator>
#include <map>
using namespacestd;
const int maxn =1e5 + 5;
int main()
{
int n;
cin >> n;
set<int> st;
map<int,int> tm;
set<int>::iterator it1,it2;
int tmp;
scanf("%d",&tmp);
int te =0;
st.insert(tmp);
tm[0] = te ++;
for (int i =1; i < n; i ++) {
scanf("%d",&tmp);
it1 = st.lower_bound(tmp);
if(it1 == st.begin())printf("%d",*it1);
elseif(it1 == st.end())printf("%d",*(--it1));
else {
it2 = it1;it1 --;
if(tm[*it1] > tm[*it2])printf("%d",*(it1));
elseprintf("%d",*(it2));
}
if(i == n -1) printf("\n");
elseprintf(" ");
st.insert(tmp);
tm[tmp] = te ++;
}
return0;
}
- 二叉排序树--cf675d Tree construction
- Tree Construction
- hdu 3516 Tree Construction
- HDOJ 3516 Tree Construction
- hdu3516 Tree Construction
- codeforces round353 tree construction
- 【DP】 HDOJ 3516 Tree Construction
- STL乱搞 Codeforces675D Tree Construction
- codeforces 353 div2 Tree Construction
- codeforces-675D Tree Construction
- hdu 3516 Tree construction DP+四边形不等式
- HDU 3516 Tree Construction (四边形优化DP)
- hdu 3516 Tree Construction(四边形优化)
- Tree Construction - HDU 3516 四边形不等式优化
- HDU - 3516 Tree Construction(四边形优化)
- Codeforces 675D Tree Construction (splay)
- Codeforces 675D Tree Construction【构造,BST】
- codeforces 675D Tree Construction(set)
- GG and MM
- RecyclerView点击事件
- POJ-3984迷宫问题 (BFS,水题)
- POJ2251 BFS
- 刷题打卡2 UVa1590,UVa508, UVa509
- 二叉排序树--cf675d Tree construction
- P3741 honoka的键盘
- Python字典对象实现原理
- 8.10关于二维数组
- 8.10
- 操作数据库(增删改查)
- Python 身份运算符
- 自我的检讨
- 解析STM32启动<转载>