摘要: 题目传送门 一、二叉树+bfs解法 #include <bits/stdc++.h> using namespace std; typedef pair<int, int> PII; const int N = 210; bool st[N]; //是不是走过了 int n, ans = 0x3f3 阅读全文
posted @ 2021-08-02 15:40 糖豆爸爸 阅读(104) 评论(0) 推荐(0)
摘要: 题目传送门 一、数组+lower_bound+upper_bound模拟 #include <bits/stdc++.h> using namespace std; const int N = 10010; int a[N]; int q, cmd, number, cnt; long long p 阅读全文
posted @ 2021-08-02 14:01 糖豆爸爸 阅读(281) 评论(0) 推荐(0)
摘要: 二叉树的三种遍历方式 一、二叉树的前序、中序、后序遍历 二叉树遍历分为三种:前序、中序、后序,其中序遍历最为重要。为啥叫这个名字?是根据根节点的顺序命名的。 规则: 前中后序是对根而言的,前就是先说根是啥,中就是中间说根是啥,后是最后说根是啥。 除根以外,其它同级节点的遍历顺序是先左后右。 举栗子: 阅读全文
posted @ 2021-08-02 11:14 糖豆爸爸 阅读(2746) 评论(0) 推荐(0)
摘要: 题目传送门 一、已知后序+中序,求前序 求解步骤: (1)后序遍历的字符串,尾字母是子树的根。 (2)在中序遍历字符串中找到“步骤1查找到的尾字母”,它的左边就是左子树,右边就是右子树,可以计算获得左子树长度$cnt=i-l2$。 (3)在后序遍历字符串中根据左子树长度,获取到左子树子串(\(l1 阅读全文
posted @ 2021-08-02 10:53 糖豆爸爸 阅读(1087) 评论(0) 推荐(1)
摘要: 题目传送门 一、已知前序+中序,求后序 (1)、二叉树的遍历,就是一个深度优先搜索的过程: 前序 const int N = 1e6 + 10; //树的结构体+存储数组 struct Node { int id; // 当前结点ID int left; // 左结点ID int right;// 阅读全文
posted @ 2021-08-02 08:23 糖豆爸爸 阅读(574) 评论(1) 推荐(2)
Live2D