当前位置:网站首页>Complete binary search tree (30 points)
Complete binary search tree (30 points)
2022-04-23 08:41:00 【Huaihua second affectionate】
A sequence of nonnegative integers without repetition , It must correspond to a unique binary search tree with the shape of a complete binary tree . This problem requires you to output the sequence traversal sequence of this tree .
Input format :
First, the first line gives a positive integer N(≤1000), Then the second line gives N A non repeating nonnegative integer . Numbers are separated by spaces , All figures do not exceed 2000.
Output format :
Output the sequence traversal sequence of the tree in one line . Between the numbers 1 Space separation , There must be no extra space at the beginning and end of the line .
sample input :
10
1 2 3 4 5 6 7 8 9 0
sample output :
6 3 8 1 5 7 9 0 2 4
#include<bits/stdc++.h>
using namespace std;
int g[1010],in[1010];
int id,n;
void pre(int root){
if(root>n)return;
pre(root*2);
in[root]=g[id++];
pre(root*2+1);
}
int main(){
cin>>n;
for(int i=0;i<n;i++)cin>>g[i];
sort(g,g+n);
pre(1);
cout<<in[1];
for(int i=2;i<=n;i++)cout<<" "<<in[i];
}
版权声明
本文为[Huaihua second affectionate]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230835222633.html
边栏推荐
- flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
- 增强现实技术是什么?能用在哪些地方?
- synchronized 锁的基本用法
- DOM learning notes - traverse all element nodes of the page
- idea底栏打开services
- SYS_ CONNECT_ BY_ Path (column, 'char') combined with start with connect by prior
- cadence的工艺角仿真、蒙特卡洛仿真、PSRR
- xctf刷题小记
- 请提前布局 Star Trek突破链游全新玩法,市场热度持续高涨
- Large amount of data submitted by form post
猜你喜欢

GUI编程简介 swing

Get the absolute path of the class according to the bytecode

让地球少些“碳”息 度能在路上

Noyer électronique stm32 Introduction à l'Internet des objets 30 étapes notes I. différences entre la Bibliothèque Hal et la Bibliothèque standard

STM32使用HAL库,整体结构和函数原理介绍

使用flask和h5搭建网站/应用的简要步骤

OneFlow學習筆記:從Functor到OpExprInterpreter

1099 establish binary search tree (30 points)

【58】最后一个单词的长度【LeetCode】

《深度学习》学习笔记(八)
随机推荐
请提前布局 Star Trek突破链游全新玩法,市场热度持续高涨
经典题目刷一刷
LINQ学习系列-----1.4 匿名对象
RPC过程
根据字节码获取类的绝对路径
关于数组复制问题
jsp页面编码
PgSQL wants to implement all kinds of column sub query operations of MySQL
Go语言自学系列 | golang方法
Use of Arthas in JVM tools
对li类数组对象随机添加特性,并进行排序
Type anonyme (Principes fondamentaux du Guide c)
DOM学习笔记---遍历页面所有元素节点
洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
PDF with watermark
mycat配置
Yangtao electronic STM32 Internet of things entry 30 step notes IV. engineering compilation and download
增强现实技术是什么?能用在哪些地方?
求简单类型的矩阵和
Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing