当前位置:网站首页>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
边栏推荐
- Innovation training (XII) reptile
- MySQL - index
- [WinUI3]编写一个仿Explorer文件管理器
- DIY is an excel version of subnet calculator
- 深度学习笔记 —— 语义分割和数据集
- Golang memory escape
- QPushbutton 槽函数被多次触发
- TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
- [2022 ICLR] Pyraformer: Low-Complexity Pyramidal Attention for Long-Range 时空序列建模和预测
- 【数据库】表的查看、修改和删除
猜你喜欢
深度学习笔记 —— 数据增广
Set Chrome browser background to eye protection (eye escort / darkreader plug-in)
Backup MySQL database with Navicat
Thoughts on a small program
AQS source code reading
[winui3] Écrivez une copie du gestionnaire de fichiers Explorer
[2022 ICLR] Pyraformer: Low-Complexity Pyramidal Attention for Long-Range 时空序列建模和预测
Cross border e-commerce | Facebook and instagram: which social media is more suitable for you?
《2021多多阅读报告》发布,95后、00后图书消费潜力攀升
Nacos source code startup error report solution
随机推荐
Summary of MySQL knowledge points
What are the redis data types
Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘
Acid of MySQL transaction
什么是指令周期,机器周期,和时钟周期?
In aggregated query without group by, expression 1 of select list contains nonaggregated column
[WinUI3]编写一个仿Explorer文件管理器
Installing kuberneters using kubedm
Get the number of days between dates, get the Chinese date, get the date of the next Monday of the date, get the working day, get the rest day
MySQL foreign key constraint
L2-011 play binary tree (build tree + BFS)
Basic concepts of multithreading (concurrency and parallelism, threads and processes) and entry cases
Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
JS détermine si la chaîne de nombres contient des caractères
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
leetcode——启发式搜索
A trinomial expression that causes a null pointer
JS engine loop mechanism: synchronous, asynchronous, event loop
Informatics Olympiad 1955: [11noip popularization group] Swiss round | openjudge 4.1 4363: Swiss round | Luogu p1309 [noip2011 popularization group] Swiss round