![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PTA
七号门房
这个作者很懒,什么都没留下…
展开
-
1099 Build A Binary Search Tree (30 分)
![在这里插入图片描述](https://img-blog.csdnimg.cn/e69620e464be4faa9f770b0592ba5307.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ4MDgxNTA5,size_16,color_FFFFFF,t_70 思路 首先题目给出的是结点的编号,所以用二叉树的静态遍历比较方便 其次,由原创 2021-08-10 10:13:07 · 48 阅读 · 0 评论 -
1064 Complete 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 · 36 阅读 · 0 评论 -
1043 Is It a Binary Search Tree (25 分)
思路 1)首先按照题目给出的顺序构造二叉排序树。注意构造的时候初始 node root=NULL 2)运用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 · 46 阅读 · 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 · 59 阅读 · 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 · 53 阅读 · 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 · 41 阅读 · 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 · 40 阅读 · 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 · 47 阅读 · 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 · 77 阅读 · 0 评论