当前位置:网站首页>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
边栏推荐
- Deep learning notes - data expansion
- 信息学奥赛一本通 1955:【11NOIP普及组】瑞士轮 | OpenJudge 4.1 4363:瑞士轮 | 洛谷 P1309 [NOIP2011 普及组] 瑞士轮
- Agile practice | agile indicators to improve group predictability
- In aggregated query without group by, expression 1 of select list contains nonaggregated column
- MySQL circularly adds sequence numbers according to the values of a column
- Making message board with PHP + MySQL
- On distributed lock
- Leetcode 1547: minimum cost of cutting sticks
- 【数据库】MySQL基本操作(基操~)
- 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
猜你喜欢

使用zerotier让异地设备组局域网

Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘

Redis persistence

MySQL slow query

Discussion on flow restriction

MySQL 慢查询

Learning Android from scratch -- Introduction
![[2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction](/img/7c/51ac43080d9721f1bdc1cd78cd685b.png)
[2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction

MySQL - index

深度学习笔记 —— 数据增广
随机推荐
Restful toolkit of idea plug-in
API slow interface analysis
持续集成(CI)/持续交付(CD)如何彻底改变自动化测试
Harmonious dormitory (linear DP / interval DP)
MySQL uses or to query SQL, and SQL execution is very slow
Redis lost key and bigkey
Live delivery form template - automatically display pictures - automatically associate series products
The difference between static pipeline and dynamic pipeline
JS détermine si la chaîne de nombres contient des caractères
Summary of R & D technology
The applet calls the function of scanning QR code and jumps to the path specified by QR code
深度学习笔记 —— 数据增广
2022/4/22
[database] MySQL basic operation (basic operation ~)
MySQL - index
Servlet3 0 + event driven for high performance long polling
Analysis of POM files
Define defines constants and macros, pointers and structures
Innovation training (XI) airline ticket crawling company information
Chapter III project schedule management of information system project manager summary