![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
dfs
limboWang
这个作者很懒,什么都没留下…
展开
-
PAT甲级-1087 All Roads Lead to Rome (30 分)
题目:1087 All Roads Lead to Rome (30 分) 分析:根据题意DFS即可,只不过城市名是字符串,用map。 #include <iostream> #include<cstring> #include<vector> #include<stdio.h> #include<queue> #include<math.h> #include<stack> #include<algorithm&.原创 2021-02-07 16:11:32 · 100 阅读 · 0 评论 -
PAT甲级-1072 Gas Station (30分)(迪杰斯特拉算法即可,DFS会超时)
题目:1072 Gas Station (30分) 分析:路径问题,用DFS会超时,使用迪杰斯特拉得出dis数组即可。注意!!!有个小坑:station不只是1-9,有可能是两位数以上,10,11,等等,因此在输入的时候字符串的处理要注意,不然最后一个测试点会报错。 AC代码(dj): #include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include .原创 2021-01-31 19:05:07 · 183 阅读 · 0 评论 -
PAT甲级-1053 Path of Equal Weight (30分)
题目:1053 Path of Equal Weight (30分) 分析:排序题,这里输出的时候直接sort,没有写cmp函数,则从尾部开始输出,或者也可以在输入的时候对每个节点的孩子进行sort(很多博客都是这样写的,代码都一样,但还是要根据自己的思路来比较好) #include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <stack&.原创 2021-01-24 15:03:04 · 118 阅读 · 0 评论 -
PAT甲级-1021 Deepest Root(25分)
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805482919673856 分析:找出以某个节点为根时,最深的根,这题可能会超时要用vector来表示二维数组 疑问:代码一是第二次写的超时了,代码二是第一次写的AC了,找不出超时代码的问题,难受o(╥﹏╥)o 代码一:超时了 #include <iostream> #include<cstring> #include<vector> .原创 2021-01-19 15:02:48 · 217 阅读 · 0 评论 -
PAT甲级-1030 Travel Plan (30分)
题目:1030 Travel Plan (30分)) 分析:单纯的DFS,记录路径,最短dis和最小cost #include <iostream> #include<cstring> #include<vector> #include<stdio.h> #include<queue> #include<math.h> #include<stack> #include<algorithm> #include&.原创 2021-01-20 14:17:51 · 68 阅读 · 0 评论