当前位置:网站首页>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<
}
边栏推荐
猜你喜欢
Why don't suggest you run in Docker Mysql?
微服务【同步和异步通讯详解】第6章
基于 LSTM 的分布式能源发电预测(Matlab代码实现)
The technical aspects of the byte have been passed, and the salary has been negotiated for 20K*13, but the result is still being brushed. I asked the HR why...
dlopen failed: library “libtaml.so“ not found
线程的同步与互斥
Characteristics of the (CAS:1527486-16-3TAMRA-azide-PEG3-Biotin) reaction in biotin azide!
【猜凶手,猜名次,杨辉三角】经典小学奥数的代码逻辑是什么?
Mysql数据库 ALTER 基本操作
组件传值-作用域插槽
随机推荐
WPF DataGrid 使用数据模板
const修饰指针的三种情况
3.9 - 正规表达式和正规集 3.10 - 有限自动机
断开和服务器共享连接的方法「建议收藏」
基于 LSTM 的分布式能源发电预测(Matlab代码实现)
3.4 - 编译与解释 3.5 - 编译过程 3.8 - 文法
Involved in PEG-Biotin (CAS: 1778736-18-7) Biotin-PEG4-OH is widely used in molecular target detection
What should I do if there is no sound after reinstalling the system in win10?
WPF DataGrid using data templates
deepstream学习笔记(三):deepstream-imagedata-multistream解析与接入适配yolov5模型测试
Project (7) - PolarSeg point cloud semantic segmentation
Kubernetes 开发环境比对
今日睡眠质量记录61分
ETCD快速入门-02 ETCD安装
3.1 - 程序设计语言 3.2 - 高级语言的特点及引用 3.3 - 静态/动态类型语言
数据库的备份与恢复「建议收藏」
nfs配置
[C language] Address book "Static Memory Version"
CAS:183896-00-6 (Biotin-PEG3-C3-NH2) PEG衍生物
LSTM-based distributed energy generation prediction (Matlab code implementation)