当前位置:网站首页>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;
}
边栏推荐
- 2. Hacking lab script off [detailed writeup]
- 学习open62541 --- [66] UA_String的生成方法
- Learn open62541 -- [66] UA_ Generation method of string
- Introduction to MySQL 8 DBA foundation tutorial
- Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
- (5) Gear control setting of APA scene construction
- 洛谷 P4281 [AHOI2008]紧急集合 / 聚会(树上倍增 LCA)
- Matlab processing of distance measurement of experimental electron microscope
- MySQL lethal serial question 4 -- are you familiar with MySQL logs?
- 4. Random variables
猜你喜欢
[AI application] Hikvision ivms-4200 software installation
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
(五)APA场景搭建之挡位控制设置
UVM learning - object attribute of UVM phase
Sus system availability scale
2022-06-17
简洁、快速、节约内存的Excel处理工具EasyExcel
华为AppLinking中统一链接的创建和使用
(5) Gear control setting of APA scene construction
华为游戏初始化init失败,返回错误码907135000
随机推荐
一招快速实现自定义快应用titlebar
洛谷 P4281 [AHOI2008]紧急集合 / 聚会(树上倍增 LCA)
Session cookies and tokens
Start class, data analysis, high salary training plan, elite class
Point cloud projection picture
实验电镜距离测量之Matlab处理
HDU1234 开门人和关门人(水题)
二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
Special topic of binary tree -- acwing 19 The next node of the binary tree (find the successor of the node in the tree)
UVM——Callback
【快应用】Win7系统使用华为IDE无法运行和调试项目
【AppLinking实战案例】通过AppLinking分享应用内图片
PCL projection point cloud
js promise. all
MySQL lethal serial question 3 -- are you familiar with MySQL locks?
PCL extracts a subset from a point cloud
Hdu1228 a + B (map mapping)
[SUCTF2018]followme
计算序列之和
Dialogue Wu Gang: why do I believe in the rise of "big country brands"?