当前位置:网站首页>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
边栏推荐
- STM32 uses Hal library. The overall structure and function principle are introduced
- 应纳税所得额
- 00后最关注的职业:公务员排第二,第一是?
- 玩转二叉树 (25 分)
- 匿名類型(C# 指南 基礎知識)
- Swagger document export custom V2 / API docs interception
- OneFlow學習筆記:從Functor到OpExprInterpreter
- php基于哈希算法出现的强弱比较漏洞
- synchronized 锁的基本用法
- Yangtao electronic STM32 Internet of things entry 30 step notes II. Cube ide download, installation, sinicization and setting
猜你喜欢

经典题目刷一刷

flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】

idea底栏打开services

Failed to convert a NumPy array to a Tensor(Unsupported Object type int)

LLVM之父Chris Lattner:编译器的黄金时代

After a circle, I sorted out this set of interview questions..

RPC procedure

洋桃电子STM32物联网入门30步笔记一、HAL库和标准库的区别

RCC introduction of Hal Library

'bully' Oracle enlarged its move again, and major enterprises deleted JDK overnight...
随机推荐
pdf加水印
Stm32f103zet6 [development of standard library functions] - Introduction to library functions
Use of Arthas in JVM tools
How to encrypt devices under the interconnection of all things
关于堆的判断 (25 分) 两种插入方式
耳穴诊疗随笔0421
ajax防止缓存方法
Queue (C language / linked list)
Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
怎样读取Excel表格到数据库
在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
Redis Desktop Manager for Mac(Redis可视化工具)
RPC procedure
[explanation] get ora-12838: cannot read / modify an object after modifying it in parallel
Misunderstanding of flush () method of OutputStream class
玩转二叉树 (25 分)
Failed to convert a NumPy array to a Tensor(Unsupported Object type int)
idea底栏打开services
让地球少些“碳”息 度能在路上