当前位置:网站首页>Traversée de l'arbre L2 - 006
Traversée de l'arbre L2 - 006
2022-04-23 02:52:00 【S atur】

Mise en œuvre du Code:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e5+10;
int n, cnt;
int bk[N], md[N];
map<int, int> pos;
struct node{
int lson, rson, val;
}tree[N];
int build(int la, int lb, int ra, int rb){
int root = bk[rb];
int k = pos[root]; // Trouver le noeud racine index
if(la < k) tree[root].lson = build(la, k-1, ra, ra+k-la-1); // Sous - arbre récursif gauche
if(lb > k) tree[root].rson = build(k+1, lb, ra+k-la, rb-1); // Sous - arbre droit récursif
return root;
}
void bfs(int root){
queue<int> q;
vector<int> ans;
q.push(root);
while(q.size()){
int t = q.front(); q.pop();
ans.push_back(t);
if(tree[t].lson) q.push(tree[t].lson);
if(tree[t].rson) q.push(tree[t].rson);
}
cout << ans[0];
for(int i = 1; i < ans.size(); i++) cout << " " << ans[i];
cout << endl;
}
signed main()
{
cin >> n;
for(int i = 1; i <= n; i ++) cin >> bk[i];
for(int i = 1; i <= n; i ++){
cin >> md[i];
pos[md[i]] = i;
}
int root = build(1, n, 1, n);
bfs(root);
return 0;
}
版权声明
本文为[S atur]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230250562858.html
边栏推荐
- Codeforces Round #784 (Div. 4) (A - H)题解
- MySQL function syntax
- grain rain
- The second day of learning rhcsa
- Error installing Mongo service 'mongodb server' on win10 failed to start
- Water diversion into chengluo Valley p1514
- 1215_ Hello world used by scons
- Encapsulate components such as pull-down menu based on ele
- Flink learning (XI) watermark
- Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl
猜你喜欢

ROP Emporium x86_ 64 7 ~ 8 questions

基于多态的职工管理系统源码与一些理解

Fashion MNIST 数据集分类训练

Flink stream processing engine system learning (II)

ele之Table表格的封装

Using go language to build web server

能做多大的单片机项目程序开发,就代表了你的敲代码的水平

Leangoo brain map - shared multi person collaborative mind mapping tool

php+mysql對下拉框搜索的內容修改

Linux Redis ——Redis HA Sentinel 集群搭建详解 & Redis主从部署
随机推荐
JVM runtime data area (I)
Shell script learning notes -- shell operation on files sed
Store consumption SMS notification template
Codeforces Round #784 (Div. 4) (A - H)题解
【Hcip】OSPF常用的6种LSA详解
Redis data server / database / cache (2022)
Log4j knowledge point record
MySQL complex query uses temporary table / with as (similar to table variable)
How big the program development of single chip microcomputer project can be, it represents your level of knocking code
基于Scrum进行创新和管理
leetcode 烹飪料理
Suggestion: block reference sorting is in the order of keywords
Rhcsa day 3 operation
Efficient music format conversion tool Music Converter Pro
Servlet template engine usage example
How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year
Rhcsa day 1 operation
Classification of technology selection (2022)
ROP Emporium x86_ 64 7 ~ 8 questions
The express project changes the jade template to art template