当前位置:网站首页>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;
}
边栏推荐
- Special topic of binary tree -- acwing 1589 Building binary search tree
- 二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)
- 华为快应用中如何实现同时传递事件对象和自定义参数
- 二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
- Common methods of JS array
- Hdu1228 a + B (map mapping)
- Read H264 parameters from mediarecord recording
- Kustomize user manual
- MySQL keyword
- Mysql database remote access permission settings
猜你喜欢

nodejs+express+mysql简单博客搭建

MySQL environment configuration

Operator-1 first acquaintance with operator

Mysql database remote access permission settings

Nodejs+express+mysql simple blog building

Open the encrypted SQLite method with sqlcipher

集成学习概览

二叉树专题--AcWing 3540. 二叉搜索树建树(实用板子 构建二叉搜索树 并输出前、中、后序遍历)

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

Disassembling Meitu SaaS: driving the plane to change the engine
随机推荐
记录 AttributeError: ‘NoneType‘ object has no attribute ‘nextcall‘
PCL之滤波
V2X-Sim数据集(上海交大&纽约大学)
华为联机对战服务玩家掉线重连案例总结
PCL projection point cloud
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
UVM - usage of common TLM port
[SUCTF2018]followme
华为快应用中如何实现同时传递事件对象和自定义参数
Learn open62541 -- [66] UA_ Generation method of string
UVM factory mechanism
MySQL environment configuration
Dialogue Wu Gang: why do I believe in the rise of "big country brands"?
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)
如何使用IDE自动签名调试鸿蒙应用
对话吴纲:我为什么笃信“大国品牌”的崛起?
HDU1234 开门人和关门人(水题)
What is the significance of the college entrance examination
Leetcode+ 76 - 80 storm search topic
Analysis of hot spots in AI technology industry