PAT甲级——A1131 Subway Map【30】】的更多相关文章

In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with your computer skills! Given the starting position of…
PAT甲级1131. Subway Map 题意: 在大城市,地铁系统对访客总是看起来很复杂.给你一些感觉,下图显示了北京地铁的地图.现在你应该帮助人们掌握你的电脑技能!鉴于您的用户的起始位置,您的任务是找到他/她目的地的最快方式. 输入规格: 每个输入文件包含一个测试用例.对于每种情况,第一行包含正整数N(<= 100),地铁线数.然后N行跟随,第i(i = 1,...,N)行以格式描述第i条地铁线: M S [1] S [2] ... S [M] 其中M(<= 100)是停止次数,S [i…
可以转到我的CSDN查看同样的文章https://blog.csdn.net/weixin_44385565/article/details/89003683 1131 Subway Map (30 分) In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing…
In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with your computer skills! Given the starting position of…
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805347523346432 题意: 告诉你一个地铁线路图,站点都是用四位数来编号. 现在问你从某一起点到某一终点,经过站数最少的乘车方式是什么?要输出方案. 如果站数相同要输出换乘较少的. 思路: 首先肯定是搜索没有问题了.因为要输出方案,所以bfs不太方便存答案.很容易想到用dfs 比较麻烦的是输出方案的时候,线路相同的那些站都合并在同一个线路里了.那么我们就再…
PAT甲级1111. Online Map 题意: 输入我们当前的位置和目的地,一个在线地图可以推荐几条路径.现在你的工作是向你的用户推荐两条路径:一条是最短的,另一条是最快的.确保任何请求存在路径. 输入规格: 每个输入文件包含一个测试用例.对于每种情况, 第一行给出两个正整数N(2 <= N <= 500),M分别是地图上街道交叉路口的总数和街道数.然后M行跟随,每个描述一个街道的格式: V1 V2单程长度时间 其中V1和V2是街道两端的索引(从0到N-1);一- 方式是1,如果街道从V1…
本文章同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90041078   1111 Online Map (30 分)   Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one i…
最短路. 记录一下到某个点,最后是哪辆车乘到的最短距离.换乘次数以及从哪个位置推过来的,可以开$map$记录一下. #include<map> #include<set> #include<ctime> #include<cmath> #include<queue> #include<string> #include<stack> #include<vector> #include<cstdio>…
Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is guaranteed that a path exists for any request. Inpu…
dfs,选择最优路径并输出~ 这道题难度非常炸裂,要求完完整整自己推一遍,DFS才算过关!思路:一遍dfs,过程中要维护两个变量,minCnt 中途停靠最少的站.minTransfer需要换成的最少次数1 可以这样算出一条线路的换乘次数:在line数组里保存每两个相邻站中间的线路是几号线,从头到尾遍历最终保存的路径,preLine为前一小段线路编号,如果当前的节点和前一个节点组成的这条路的编号和preLine不同,说明有一个换乘,就将cnt+1,最后遍历完累加的cnt即是换乘的次数.2 line…