BFS
文章平均质量分 85
新西兰做的饭
Here we go!
展开
-
通过四道编程题总结图的搜索(DFS/BFS)——PTA(1013/1021/1034/1076)
1013 Battle Over Cities (25 分)It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other hig原创 2022-02-28 01:19:45 · 559 阅读 · 0 评论 -
PTA-二叉查找树(1043/1064/1099)
1043 Is It a Binary Search Tree (25 分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node’s key.The right subtree of a node co.原创 2022-02-06 18:42:14 · 812 阅读 · 0 评论 -
PTA-树的遍历(1079/1090/1094/1106/1004/1053)
1079 Total Sales of Supply Chain (25 分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys pro.原创 2022-01-22 15:45:35 · 925 阅读 · 0 评论 -
PTA-二叉树的遍历(1020/1086/1102)
1020 Tree Traversals (25 分)Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.Inpu原创 2022-01-19 15:56:01 · 1344 阅读 · 0 评论 -
PTA-BFS(1091)
1091 Acute Stroke (30 分)One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the stro原创 2022-01-16 11:10:07 · 332 阅读 · 0 评论 -
LeetCode102:二叉树的层序遍历(BFS)
二叉树的层序遍历BFS经典的应用,值得记录下来。首先将根结点压入队列,只要队列非空就进行循环:为了按照层序输出结点,我们将当前队列长度取出,然后进行循环,这样做的目的是每次进行for循环都是将当前层取出,然后将当前层所有的儿子结点(下一层)压入队列。循环时取出值并弹出元素,当队列为空时即遍历完毕。class Solution {public: vector<vector<int>> levelOrder(TreeNode* root) { if(原创 2021-05-12 20:09:44 · 111 阅读 · 1 评论 -
图文详解图的表示及DFS和BFS
#define MAXVEX 100#define INFINITY 65535//邻接矩阵typedef struct { char vexs[MAXVEX]; int arc[MAXVEX][MAXVEX]; int numVerTexes,numEdges;}MGraph;//建立无向网图的邻接矩阵void CreateMGraph(MGraph *G){ int x,y,w; cout<<"输入顶点数和边数:"<<endl; cin>>原创 2021-05-10 10:40:12 · 2164 阅读 · 0 评论