首页 > 牛牛走迷宫
头像 Kur1su
发表于 2020-06-21 20:08:02
Description 牛牛周末去了游乐园走迷宫。这是一个n*m大小的01迷宫,0表示这个位置可以走,1表示有障碍物不能。走。现在牛牛在起点(1,1),他想要走到终点(n,m)。并且,如果他能够走到终点的话,他想要知道自己是怎么走到终点的。如果可以走到终点,因为牛牛比较懒他会先保证走的步数最少,又因 展开全文
头像 憨憨的竹林
发表于 2026-05-23 01:24:43
这题简单捏,写一个 bfs 就好啦 可以写一个结构体来维护当前的步数,坐标,以及操作指令 为了让字典序最小,可以以 D、L、R、U 的顺序去遍历,这样能够保证走出的最短路一定字典序最小 代码如下: #include <bits/stdc++.h> using namespace std; 展开全文
头像 东溪看水
发表于 2020-06-23 15:48:58
解题思路 有一个 n * m 大小的01迷宫,0表示这个位置可以走,1表示有障碍物不能走。现在需要从起点 (1,1) 走到终点 (n,m)。如果可以走到终点,求出走的最少步数,并记录如何走到终点的。如果有多条路径步数一样,选择走字典序最小的那条。数据保证起点和终点都是 0。 使用 BFS 算法,并将 展开全文
头像 cheeserish
发表于 2020-06-22 12:46:15
路径查询写的有点麻烦;可以直接用结构体,记录前一个路径;思想就是,走迷宫,最少路径bfs;字典序最小,按照D L R U的顺序遍历就行了 #include<bits/stdc++.h> using namespace std; int vis[251000]; char mp[1010] 展开全文
头像 IA3000
发表于 2026-05-23 00:25:26
#include <bits/stdc++.h> using namespace std; const int N = 505, inf = 1e9; const int dir[] = {1,0,-1,0,1}; int n, m; int d[N][N]; char mat[N] 展开全文
头像 BeauWill
发表于 2026-05-23 13:50:46
Modern Cpp #include <iostream> #include <vector> #include <array> #include <string> #include <queue> #include <map> 展开全文
头像 腌萝卜干
发表于 2026-05-23 13:51:19
逆序处理, 从前向后贪心, 每次选择字典序最小的字符加入到操作集合 #include <bits/stdc++.h> #define x first #define y second #define all(x) x.begin(), x.end() #define vec1(T, n 展开全文
头像 guotjsd
发表于 2026-05-23 18:46:29
按照题目要求顺序bfs遍历,使用map存当前点从哪个节点过来的,得到的路径字符串反转后就是正向路径 #include <iostream> #include <type_traits> #include<vector> #include<queue> 展开全文