当前位置:网站首页>Minimum number of steps to get out of the maze 2
Minimum number of steps to get out of the maze 2
2022-08-10 01:47:00 【-JMY-】
Title description
When you're standing in a maze, you tend to get disoriented by the intricate paths, and if you can get your hands on a map of the maze, it's really easy.Suppose you have obtained a drawing of an n*m maze, please find the shortest path from the starting point to the exit.
Enter
The first line is two integers n and m (1<=nm<=100), which represent the number of rows and columns of the maze.The next n lines, each with a string of length m, represent the layout of the entire maze.The characters '.' represent open spaces, '#' represent walls, 'S' represent starting points, and 'T' represent exits.
Output
Output the minimum number of steps required to travel from the starting point to the exit.
Sample input
3 3S#T.#....
Sample output
6
Reference code:
#include
using namespace std;
int n,m;
int q[5000][2],hh,tt,kx,ky,l,gx,gy;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int d[50][50];
char a[50][50];
void bfs(){
while(hh!=tt){
kx=q[hh][1];
ky=q[hh][0];
hh++;
for(int i=0;i<4;i++){
int xx=kx+dx[i];
int yy=ky+dy[i];
if(xx>=0&&xx
q[tt-1][0]=yy;
q[tt-1][1]=xx;
d[yy][xx]=d[ky][kx]+1;
cin>>n>>m;
for(int i=0;i
for(int i=0;i
q[0][0]=i;
q[0][1]=j;
d[i][j]=1;
if(a[i][j]=='T'){
gx=j;
gy=i;
cout<
}
边栏推荐
猜你喜欢
3.1 - 程序设计语言 3.2 - 高级语言的特点及引用 3.3 - 静态/动态类型语言
为什么不建议你在 Docker 中跑 Mysql ?
D-Biotinol Involved by Biotin, CAS No: 53906-36-8 Specific Properties Description
7. type( )函数——查询数据类型
服装店管理系统如何推送活动?
基于 LSTM 的分布式能源发电预测(Matlab代码实现)
LSTM-based distributed energy generation prediction (Matlab code implementation)
Why don't suggest you run in Docker Mysql?
dlopen failed: library "libtaml.so" not found
Leetcode79. 单词搜索
随机推荐
天猫全网商品详情封装接口
LeetCode常见题型——链表
arm-4-裸板开发
【问题解决】训练和验证准确率很高,但测试准确率很低
Leetcode80. 删除有序数组中的重复项 II
【毕业设计】基于ESP32的在线墨水屏桌面摆件 -物联网 单片机 嵌入式
Characteristics of the (CAS:1527486-16-3TAMRA-azide-PEG3-Biotin) reaction in biotin azide!
const修饰指针的三种情况
Today's sleep quality record 61 points
深入理解Aarch64内存管理
03|流程控制
Koa中间件next实现
Web性能测试模型小结
-采花生-
Next.js获取路由参数及styled-jsx 的使用
温度响应性纳米水凝胶光子品体/纤维素修饰荧光水凝胶/载脂质体水凝胶的制备方法
-Vector Dot Product-
【CAS:41994-02-9 |Biotinyl tyramide】生物素基酪氨酰胺价格
有PEG-Biotin参与的(CAS:1778736-18-7)Biotin-PEG4-OH广泛用于分子靶点检测
渗透测试与攻防对抗——漏洞扫描&逻辑漏洞(Part1)