
PTA
七号门房
这个作者很懒,什么都没留下…
展开
-
1099 Build A Binary Search Tree (30 分)

思路1)当要求完全二叉树时,该二叉树的形态已经固定,我们定义了一个CBT数组用来层次存储二叉树的结点。2)由于要求是二叉排序树,又因为二叉排序树的中序遍历结果是个有序的数列,因此可以先将输入的数组排序,再依次填入CBT数组,最后遍历输出即可。#include <cstdio>#include <vector>#include <algorithm>const int maxen = 1010;using namespace std;int CBT[maxe原创 2021-08-09 18:18:52 · 68 阅读 · 0 评论 -
1043 Is It a Binary Search Tree (25 分)
思路1)首先按照题目给出的顺序构造二叉排序树。注意构造的时候初始 node root=NULL2)运用STL中的vector分别求出该二叉树的先序遍历,后序遍历,镜像序列以及镜像序列的后序遍历#include <cstdio>#include <vector>using namespace std;struct node{ int data; node* lchild; node* rchild;};//插入结点void insert(n原创 2021-08-09 16:47:40 · 76 阅读 · 0 评论 -
二叉查找树基本操作
#include <cstdio>using namespace std;struct node{ int data; node* lchild; node* rchild;};//查找操作void search(node *root,int x){ if(root==NULL) { printf("Failed"); return; } if(x==root->data) {原创 2021-08-09 14:30:28 · 101 阅读 · 0 评论 -
1004 Counting Leaves (30 分)
#include <cstdio>#include <iostream>#include <vector>#include <queue>const int maxen = 110;using namespace std;struct node{ int layer; vector<int> child;}Node[maxen];int n;void BFS(int root);int hashTable[m原创 2021-08-09 09:32:28 · 79 阅读 · 0 评论 -
1094 The Largest Generation (25 分)
思路本题思路主要是通过层次遍历得出每一个结点的层次,接着求出同一层次结点的个数,最后便可以得出答案#include <cstdio>#include <iostream>#include <vector>#include <queue>const int maxen = 110;using namespace std;struct node{ int layer; vector<int> child;}Node原创 2021-08-08 21:50:33 · 72 阅读 · 0 评论 -
1090 Highest Price in Supply Chain (25 分)
#include <iostream>#include <vector>#include <string>#include <algorithm>#include <queue>#include <cmath>const int maxen = 100010;using namespace std;struct node{ int layer; vector<int> child;}Nod原创 2021-08-08 18:05:15 · 65 阅读 · 0 评论 -
1079 Total Sales of Supply Chain (25 分)
思路1) 题目的关键点在于找出每个叶子节点的层次,可以通过层序遍历来实现。2)层序遍历可以通过队列的方式实现,同时在遍历的同时,对每个节点的层次进行标记#include <iostream>#include <vector>#include <string>#include <algorithm>#include <queue>#include <cmath>const int maxen = 100010;usi.原创 2021-08-08 17:02:53 · 76 阅读 · 0 评论 -
PTA 1053 Path of Equal Weight (30 分)
PTA 1053 Path of Equal Weight (30 分)思路使用树的静态表示方法,进行构造通过DFS回溯,遍历整棵树,如果权重达到目标则进行保存。#include <iostream>#include <vector>#include <string>#include <algorithm>const int maxen = 110;using namespace std;void DFS(int root ,int s原创 2021-08-08 11:15:07 · 115 阅读 · 0 评论