当前位置:网站首页>Binary tree topic -- p1030 [noip2001 popularization group] find the first order
Binary tree topic -- p1030 [noip2001 popularization group] find the first order
2022-07-02 10:59:00 【Morgannr】
[NOIP2001 Popularization group ] Find the precedence
Title Description
In this paper, we give the middle order and the back order of a binary tree . Find out its precedence .( Convention tree nodes are represented by different capital letters , length $ \le 8$).
Input format
2 2 2 That's ok , A string of uppercase letters , Represents the middle and back order of a binary tree .
Output format
1 1 1 That's ok , Represents the precedence of a binary tree .
Examples #1
The sample input #1
BADC
BDCA
Sample output #1
ABCD
Tips
【 Title source 】
NOIP 2001 Third question of popularization group
#define _CRT_SECURE_NO_WARNINGS 1
#include <bits/stdc++.h>
using namespace std;
//#define int long long
//#define map unordered_map
const int N = 10;
map<char, int> l, r, d;
char in[N], post[N];
int dfs1(int il, int ir, int pl, int pr)
{
if (pl > pr) return -1;
char root = post[pr];
int k = d[root];
l[root] = dfs1(il, k - 1, pl, k - 1 - il + pl);
r[root] = dfs1(k + 1, ir, k - il + pl, pr - 1);
return k;
}
void dfs2(int u)
{
if (u == -1) return;
cout << in[u];
if (l[in[u]] != -1) dfs2(l[in[u]]);
if (r[in[u]] != -1) dfs2(r[in[u]]);
}
signed main()
{
int T = 1; //cin >> T;
while (T--)
{
cin >> in >> post;
for (int i = 0; in[i]; ++i)
{
d[in[i]] = i;
}
int n = strlen(in);
int root = dfs1(0, n - 1, 0, n - 1);
dfs2(root);
puts("");
}
return 0;
}
边栏推荐
- V2X-Sim数据集(上海交大&纽约大学)
- PCL eigen introduction and simple use
- LabVIEW为什么浮点数会丢失精度
- Operator-1 first acquaintance with operator
- 14. Code implementation of semaphore
- 软件产品管理系统有哪些?12个最佳产品管理工具盘点
- 二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
- UVM - configuration mechanism
- [SUCTF2018]followme
- 1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
猜你喜欢

Read H264 parameters from mediarecord recording

二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)

二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)

华为应用市场应用统计数据问题大揭秘

Easyexcel, a concise, fast and memory saving excel processing tool

JSP webshell free -- the basis of JSP

Hdu1236 ranking (structure Sorting)

V2X-Sim数据集(上海交大&纽约大学)
![2. Hacking lab script off [detailed writeup]](/img/f3/29745761cd5ad4df84c78ac904ea51.png)
2. Hacking lab script off [detailed writeup]

Open the encrypted SQLite method with sqlcipher
随机推荐
Shell programming 01_ Shell foundation
14. Code implementation of semaphore
HDU1228 A + B(map映射)
[TS] 1368 seconds understand typescript generic tool types!
JSP webshell免殺——JSP的基礎
Oracle 笔记
华为应用市场应用统计数据问题大揭秘
Read H264 parameters from mediarecord recording
Hdu1234 door opener and door closer (water question)
UVM - usage of common TLM port
Point cloud projection picture
What are the popular frameworks for swoole in 2022?
12. Process synchronization and semaphore
【AGC】构建服务3-认证服务示例
PCL 点云转深度图像
MySQL lethal serial question 3 -- are you familiar with MySQL locks?
记录 AttributeError: ‘NoneType‘ object has no attribute ‘nextcall‘
力扣(LeetCode)182. 查找重复的电子邮箱(2022.07.01)
2022-06-17
PCL eigen introduction and simple use