当前位置:网站首页>Traversal of tree
Traversal of tree
2022-04-23 05:08:00 【FOWng_ lp】
The first sequence traversal
Brief notes : Root left and right
After the sequence traversal
Brief notes : Left and right
In the sequence traversal
Brief notes : Left root right
The first sequence traversal 21nod 1591
#include<cstdio>
#include<iostream>
using namespace std;
struct node{
int l;
int r;
};
struct node N[100005];
void search(int cnt){
if(cnt==0)return;
cout << cnt << endl;
search(N[cnt].l);
search(N[cnt].r);
}
int main(){
int n,a,b;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a >> b;
N[i].l = a;
N[i].r = b;
}
search(1);
return 0;
}
Subsequent traversal 51node 2350
#include<cstdio>
#include<iostream>
using namespace std;
struct node{
int l;
int r;
};
struct node N[100005];
int ct[100005];
void search(int cnt){
if(cnt==0)return;
search(N[cnt].l);
search(N[cnt].r);
cout << cnt << endl;
}
int main(){
int n,a,b;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a >> b;
N[i].l = a;
N[i].r = b;
}
search(1);
return 0;
}
POJ 2499
http://poj.org/problem?id=2499
The main idea of the topic
Finding the minimum path of binary tree with special structure
Each node is (a,b) Number pair , Its child node must be left (a+b,b) The right child node must be (a,a+b), The root node is (1,1). Ask to reach the specified node (a,b) The minimum number of walks , How many times do I need to go to the left child node , How many times to the right child node .
Note that this binary tree can be constructed by itself !
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
int n,a,b,ans1,ans2;
cin >> n;
for(int i = 1;i <= n;i++){
cout << "Scenario #"<<i<<':'<<endl;
cin >> a >> b;
// cout << a << " ok "<< b <<endl;
ans1 = 0,ans2=0;
while(a!=1||b!=1){
//qcout<< "ok" <<endl;
if(a==b){
ans1+=(a-1);
ans2+=(b-1);
break;
}
if(a==1||b==1){
ans1+=(a-1);
ans2+=(b-1);
break;
}
if(a>b){
ans1 += a / b;
a = a%b;
}
if(b>a){
ans2 += b/a;
b = b%a;
}
}
cout << ans1 << ' ' << ans2 <<endl;
cout <<endl;
}
return 0;
}
HUD 1710
http://acm.hdu.edu.cn/showproblem.php?pid=1710
版权声明
本文为[FOWng_ lp]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220549345475.html
边栏推荐
- The 8 diagrams let you see the execution sequence of async / await and promise step by step
- [WinUI3]编写一个仿Explorer文件管理器
- MySQL views the SQL statement details executed by the optimizer
- Sword finger offer: symmetric binary tree (recursive iteration leetcode 101)
- Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
- Independent station operation | Facebook marketing artifact - chat robot manychat
- 【数据库】MySQL基本操作(基操~)
- Innovation training (XI) airline ticket crawling company information
- [database] MySQL basic operation (basic operation ~)
- MySQL - index
猜你喜欢
Spell it! Two A-level universities and six B-level universities have abolished master's degree programs in software engineering!
[winui3] write an imitation Explorer file manager
Restful toolkit of idea plug-in
Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
Deep learning notes - data expansion
Use the built-in function of win to transfer files between two computers in the same LAN (the speed is the same as that between local disks)
[2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction
Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘
MySQL memo (for your own query)
随机推荐
Deep learning notes - fine tuning
Other problems encountered in debugging fingerprints
洛谷P2731骑马修栅栏
The WebService interface writes and publishes calls to the WebService interface (I)
Redis lost key and bigkey
Chapter III project schedule management of information system project manager summary
What are instruction cycles, machine cycles, and clock cycles?
View, modify and delete [database] table
Learning Android from scratch -- Introduction
【数据库】MySQL单表查询
Sword finger offer: symmetric binary tree (recursive iteration leetcode 101)
Basic theory of Flink
AQS源码阅读
TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
Set Chrome browser background to eye protection (eye escort / darkreader plug-in)
MySQL basics 3
Chapter II project scope management of information system project manager summary
scp命令详解
The vscode ipynb file does not have code highlighting and code completion solutions
机器学习---线性回归