上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 74 下一页

2025年11月29日

二叉树的深度

摘要: 题目描述:输入一棵二叉树,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。 思路:通过广度优先遍历(BFS)来获取二叉树的深度。 步骤: 1 如果根结点为空,则返回0。 2 创建实现了Queue接口的LinkedList对象。 3 通过队列来执 阅读全文

posted @ 2025-11-29 15:03 王景迁 阅读(17) 评论(0) 推荐(0)

二叉树的镜像

摘要: 题目描述:操作给定的二叉树,将其变换为源二叉树的镜像。 思路:通过BFS来遍历每个结点,交换当前结点的左右孩子结点即交换左右子树。 步骤: 1 如果根结点为空或者只有一个结点,则结束。 2 创建实现了Queue接口的LinkedList对象。 3 根结点入队列。 4 通过BFS来遍历每个结点,交换当 阅读全文

posted @ 2025-11-29 15:03 王景迁 阅读(14) 评论(0) 推荐(0)

5-18 Hashing - Hard Version (30分)

摘要: #include <iostream> #include <vector> #include <queue> using namespace std; struct node { int key, index; bool operator < (const node &nod) const { re 阅读全文

posted @ 2025-11-29 15:00 王景迁 阅读(9) 评论(0) 推荐(0)

5-14 电话聊天狂人 (25分)

摘要: #include <iostream> #include <map> using namespace std; int main() { int n; scanf("%d", &n); int i; long long num; map<long long, int> m; for(i = 1; i 阅读全文

posted @ 2025-11-29 15:00 王景迁 阅读(6) 评论(0) 推荐(0)

5-11 关键活动 (30分)

摘要: #include <iostream> #include <vector> #include <queue> using namespace std; struct node { int next, time; }; int degree[2][110], t[2][110], maxtime; v 阅读全文

posted @ 2025-11-29 14:59 王景迁 阅读(7) 评论(0) 推荐(0)

5-10 公路村村通 (30分)

摘要: #include <iostream> #include <algorithm> using namespace std; struct edge { int a, b, cost; }e[3010]; int sum[1010], tree[1010], res; int cmp(edge e1, 阅读全文

posted @ 2025-11-29 14:59 王景迁 阅读(8) 评论(0) 推荐(0)

5-10 Saving James Bond - Easy Version (25分)

摘要: #include <iostream> #include <math.h> using namespace std; struct node { int x, y, flag; }vis[110]; int flag, d, n; double getdis(int index0, int inde 阅读全文

posted @ 2025-11-29 14:59 王景迁 阅读(8) 评论(0) 推荐(0)

5-9 Huffman Codes (30分)

摘要: #include <iostream> #include <queue> #include <vector> #include <string.h> using namespace std; int judge(char a[], char b[], int alen, int blen) { in 阅读全文

posted @ 2025-11-29 14:58 王景迁 阅读(14) 评论(0) 推荐(0)

5-8 哈利·波特的考试 (25分)

摘要: #include <iostream> #include <vector> #include <string.h> using namespace std; struct node { int next, dis; }; int tree[110], sum[110], flag[110]; int 阅读全文

posted @ 2025-11-29 14:58 王景迁 阅读(11) 评论(0) 推荐(0)

5-8 File Transfer (25分)

摘要: #include <iostream> using namespace std; int tree[10010], sum[10010]; void init(int n) { int i; for(i = 1; i <= n; i++) { tree[i] = -1; sum[i] = 1; } 阅读全文

posted @ 2025-11-29 14:57 王景迁 阅读(7) 评论(0) 推荐(0)

上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 74 下一页

导航