当前位置:网站首页>1086 tree traversals again (25 points)
1086 tree traversals again (25 points)
2022-07-03 04:56:00 【vs5】
Stacking is the preamble , Out of the stack is the middle order
#include <iostream>
#include <vector>
using namespace std;
const int N = 50;
int stk[N],top,f;
vector<int>pre,in;
// Stacking is the preamble , Out of the stack is the middle order
void dfs(int preL,int preR,int inL,int inR)
{
if(preL > preR) return ;
int k = inL;
while(in[k] != pre[preL]) k ++;
dfs(preL + 1,preL + k - inL,inL,k - 1);
dfs(preL + 1 + k - inL,preR,k + 1,inR);
if(f != 0) cout << ' ';
cout << pre[preL];f = 1;
}
int main()
{
int n,x,cnt = 0;
string s;
cin >> n;
while(cnt != n)
{
cin >> s;
if(s[1] == 'u')
{
cin >> x;
stk[ ++ top] = x;
pre.push_back(x);
}
else in.push_back(stk[top --]),cnt ++;
}
dfs(0,n - 1,0,n - 1);
return 0;
}
边栏推荐
- Market status and development prospect prediction of the global autonomous hybrid underwater glider industry in 2022
- Current market situation and development prospect forecast of global UV sensitive resin 3D printer industry in 2022
- Three representations of signed numbers: original code, inverse code and complement code
- 2022-02-12 daily clock in: problem fine brush
- 第十九届浙江省 I. Barbecue
- 论文阅读_清华ERNIE
- Notes | numpy-07 Slice and index
- The process of browser accessing the website
- Notes | numpy-09 Broadcast
- Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
猜你喜欢
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
Preparation for school and professional cognition
Compile and decompile GCC common instructions
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
移动端——uniapp开发记录(公共请求request封装)
Analysis of proxy usage of ES6 new feature
The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
Apache MPM model and ab stress test
First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
随机推荐
Market status and development prospects of the global automatic tea picker industry in 2022
论文阅读_中文NLP_ELECTRA
50 practical applications of R language (36) - data visualization from basic to advanced
LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)
Thesis reading_ Tsinghua Ernie
String matching: find a substring in a string
Keepalived热备与HAProxy
Why does I start with =1? How does this code work?
Leetcode simple question: the key with the longest key duration
data2vec! New milestone of unified mode
【SQL注入点】注入点出现位置、判断
Introduction to message queuing (MQ)
Compile and decompile GCC common instructions
Sdl2 + OpenGL glsl practice (Continued)
Market status and development prospect prediction of the global fire extinguisher industry in 2022
MPM model and ab pressure test
[luatos sensor] 2 air pressure bmp180
Notes | numpy-07 Slice and index
On typescript and grammar
Notes | numpy-08 Advanced index