//1020. Tree Traversals (25)
//递归
//将层次遍历存储在数组里面就ok
//accept
#include <iostream>
#include <algorithm>
using namespace std;
int PostOrder[31];
int InOrder[31];
int result[35][35] = {0};
int index[35] = {0};
int level = 0;
void recursive(int s1, int e1, int s2, int e2)
{
if (s1 > e1 || s2 > e2)
{
return;
}
int tmp = PostOrder[e1];
//cout << " " << tmp;
level++;
int* pos = find(InOrder+s2, InOrder + e2 + 1, tmp);
int end2 = pos - InOrder;
result[level][index[level]] = tmp;
index[level]++;
recursive(s1, s1 + (end2 - 1 - s2), s2, end2 -1);
recursive( s1+ end2 - s2, e1-1, end2 + 1, e2);
level--;
}
int main()
{
int N;
cin >> N;
int i;
for (i = 0;i<N;i++)
{
cin >> PostOrder[i];
}
for (i = 0;i<N;i++)
{
cin >> InOrder[i];
}
int root = PostOrder[N-1];
cout << root;
int* pos = find(InOrder, InOrder + N, root);
int end2 = pos - InOrder;
int num = end2;
level = 0;
recursive(0, end2 - 1, 0, end2 - 1);
level = 0;
recursive(end2, N-2,end2+1,N-1 );
int j;
i = 1;
while(1)
{
for (j = 0;j<index[i];j++)
{
cout << " " << result[i][j];
}
if (index[i] == 0)
{
break;
}
i++;
}
return 0;
}相关推荐
lenovo联想拯救者Legion Y9000P 2022款2023款2024款笔记本电脑(82RF,82WK,82WQ,83DE,83DF)原装出厂Windows11预装OEM系统镜像下载
联想原装出厂系统自带所有驱动、出厂主题壁纸、系统属性联机支持标志、系统属性专属LOGO标志、Office办公软件、联想电脑管家、联想浏览器、联想软件商店、legionzone控制中心等预装程序。链接:https://pan.baidu.com/s/1YBji_oh7xOkq-NxnS8Mm8g?链接:https://pan.baidu.com/s/1S7_enXmuoja1a9ASvUT5Fg?拯救者Legion Y9000P IRX9H 2024款【83DE】原厂Win11系统包。
浙大 PAT 1020. Tree Traversals (25)
1020. Tree Traversals (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppose that all the keys in a binary tree
Memory SystemsCache, DRAM, Disk翻译学习DRAM部分(二)
DRAM 的发展史
[PAT-Advanced] A1020 Tree Traversals (25)
文章目录A1020 Tree Traversals (25point(s))Input Specification:Output Specification:Sample Input:Sample Output:CodeAnalysis A1020 Tree Traversals (25point(s)) Suppose that all the keys in a binary tree are...
Vlan的封装模式和端口讲解(Access、Trunk、Hypbrid端口)
Vlan(Virtual Local Area Network)虚拟局域网,将一个物理的LAN在逻辑上划分为多个广播域,在交换机上实现广播域隔离(增强局域网的安全性、限制广播风暴、简化网络管理)Vlan通过将二层数据帧打上Vlan标签(打上Vlan标签也就是封装Vlan),正常情况下,不同Vlan Tag的数据包是无法二层直接互访的,以此来实现广播域的隔离可以理解为一个Vlan对应一个广播域,同一Vlan内的主机可以二层直接通信,不同Vlan间的主机无法二层直接通信。
SolidWorks速成教程P4-4【装配体 | 第四节】——装配体内修改模型&编辑配合方法&配合报错的解决方法
截止目前已介绍完 SolidWorks装配体的常用功能,但基础薄弱的小伙伴或许对装配体的各类功能还不够熟悉。所以这节将进一步加强装配体的学习,同时介绍新手容易犯的错误。总结出三点,一是装配体内修改模型,二是编辑配合,三是配合报错的解决方法。
PAT 1020 Tree Traversals (25 分)
1020Tree Traversals(25 分) Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order ...
多摄像头场景下 ISP 的同步与调度机制实战解析
在智能手机多摄系统中,主摄、广角、长焦、微距等摄像头的协同工作能力直接决定了影像系统的体验上限。而支撑这一能力的核心之一,正是 ISP 的同步与调度机制。ISP 需要处理多个 Sensor 的输入流、统一时序、资源仲裁、并发调度,并支持在不同模式间快速切换(如预览 → 拍照 → 视频)。本文将基于 Qualcomm、MTK、HiSilicon 平台的实际架构,系统性剖析 ISP 在多摄场景下的时序控制、Pipeline 配置、Buffer 管理与故障恢复机制,并分享实战中的典型问题与调试方案。
PAT甲级 - 1020 Tree Traversals (25 分)
题目链接:PAT甲级 - 1020 Tree Traversals (25 分) Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the...
YOLOv10改进策略【模型轻量化】| 替换骨干网络为MoblieNetV2,含模型详解和完整配置步骤
本文记录的是。采用深度可分离卷积将标准卷积分解为深度卷积和1×1卷积。同时,引入来,避免非线性层导致的性能下降问题。本文将应用到YOLOv10中,借助其高效的结构和特性,在保持一定精度的前提下,显著降低YOLOv10的计算复杂度和内存占用。
一文吃透 OData Deep Insert:从框架原理到 ABAP 实战
本文面向ABAP工程师,解析OData服务中的Deep Insert技术。文章首先阐述Deep Insert的业务背景,说明其适用于父子层级数据必须成组创建的场景(如销售订单与行项目)。随后深入框架实现机制,介绍SAP Gateway如何通过CREATE_DEEP_ENTITY方法处理嵌套请求,并强调开发者的责任边界。通过销售订单案例,文章对比了Deep Insert与$batch的适用场景差异,提供请求负载示例和DPC_EXT实现骨架代码。最后给出MPC_EXT声明深结构的三种套路,以及事务处理和错误处理
PAT 1020 Tree Traversals (25)
根据postorder后序和inorder中序遍历,求level层次遍历 后序可以得出根在集合的最后,再根据中序划分左右子树集合,递归建树 建树后bfs输出层次遍历 #include #include #include using namespace std; const int N=50; int last[N],mid[N],n,cnt=0,start[N]; queue q;
ICC2:使用analyze_lib_cell_placement检查lib cell的pass rate
我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?在place之前需要使analyze_lib_cell_placement命令去检查lib cell在当前的site row/power plan/legalize设置的环境下能够正常place和legalize。下面分享一个脚本去报告pass rate低于2%的lib cell。
Day45: [PAT甲级] 1020 Tree Traversals (25分)
Day45: [PAT甲级] 1020 Tree Traversals (25分) 题源: 来自PAT甲级题库: https://pintia.cn/problem-sets/994805342720868352/problems/994805485033603072 代码: dirty code凑合看吧 思路就是通过前序遍历和中序遍历直接把树构造好,然后层序遍历。 #include<io...
Data-Structures-and-Algorithm-Analysis-in-Java.pdf
作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
PAT甲级 1020 Tree Traversals (25 分)
题目: 戳这里 题意:已知后序、中序遍历,求层序遍历。 解题思路: 需要抓住后序、中序的遍历顺序。 后序:左右根,则根一直在最后面。 中序:左根右,则根的左边为左子树,右边为右子树。 通过后序遍历锁定根的位置; 在中序遍历中找到根,则其左边的为左子树,右边的为右子树,于是我们得到了左右子树的长度; 在后序遍历中,根的左边就是右子树的根,整个长度减去右子树的长度和跟,就是左子树,且左子树的根在最右边...
jdk-8u144-linux-x64.tar.gz.
该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包
【PAT】1020 Tree Traversals (25) [tree][traversal]
1020 Tree Traversals (25分) 后序+中序转层序 node保存结点标号,按标号升序输出 //#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<vector> #include<algorithm> using namespace std; struct node { int id;//按完全二叉树的下标 int val;//值 }; bool cmp(node a, nod
SAP B1中文培訓教材_SDK
公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说
PAT 1020 Tree Traversals(25分)
中序和后序建树+BFS
[PAT] 1020 Tree Traversals (25 分)Java
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of th...
1020. Tree Traversals (25)-PAT甲级真题
1020. Tree Traversals (25) Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level ord
PAT甲级-1020 Tree Traversals (25分)
点击链接PAT甲级-AC全解汇总 题目: Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversa...
PAT甲级 1020 Tree Traversals (25分)
1020 Tree Traversals (25分) 题目链接:PAT A 1020 题目大意:给出一棵树的后序遍历和中序遍历,要求求出该树的层序遍历。 思路分析:根据后序遍历和中序遍历可以构建出唯一的一颗二叉树,用到了递归的求解方法。对于每一棵树,后序遍历的最后一个元素就是该树的根节点,然后在中序遍历中找到这个元素,记录对应的下标,左面的元素就是这棵树的左子树,右面的树就是这棵树的右子树,然后...
1020 Tree Traversals (25分) PAT
看起来复杂,其实实现还是比较简单的。 先用递归建树,然后用队列实现输出。下面的代码样例中忘了delete。 #include<cstdio> #include<queue> using namespace std; #define maxn 35 struct node { int data; node *left, *right; }; no...
pat甲级 A1020 Tree Traversals (25分)
题目链接: https://pintia.cn/problem-sets/994805342720868352/problems/994805485033603072 题目分析: 树的遍历。通过后序序列 + 中序序列得到层序序列。 参考代码: #include<iostream> #include<vector> using namespace st...
【PAT甲级】1020 Tree Traversals (25分)
解题过程的小记录,如有错误欢迎指出。 难度:四星(写的第一道二叉树题) 小导航~题目分析注意点我的解题过程思路bug代码dalao的代码借鉴点 题目分析 给出二叉树的后序排序和中序排序数列,要求给出此二叉树的层次排序 注意点 该二叉树不是完全二叉树 我的解题过程 思路 把后序排序和中序排序的数列读入对应数组 写一个creat函数,通过上面两个数组还原二叉树 写出层次遍历函数(BFS) bug 在create函数中的root没有用new来创建(指针用得比较少手生orz) 在层次遍历的函数中,要是非空
[Java] 1020. Tree Traversals (25)-PAT甲级
1020. Tree Traversals (25)Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order tra...
[C++] PAT 1020 Tree Traversals (25分)
Sample Input: 7 2 3 1 5 7 6 4 1 2 3 4 5 6 7 Sample Output: 4 1 6 3 5 7 2 题解 给定二叉树的后序和中序遍历,输出该二叉树的层次遍历
6524



被折叠的 条评论
为什么被折叠?



