当前位置:网站首页>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<
}
边栏推荐
- 深入理解Aarch64内存管理
- FITC标记生物素(FITC-生物素|CAS:134759-22-1)有哪些知识了?
- MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
- 断开和服务器共享连接的方法「建议收藏」
- CAS:851113-28-5 (生物素-ahx-ahx-酪胺)
- 03|流程控制
- D-Biotinol Involved by Biotin, CAS No: 53906-36-8 Specific Properties Description
- 数据库的备份与恢复「建议收藏」
- Characteristics of the (CAS:1527486-16-3TAMRA-azide-PEG3-Biotin) reaction in biotin azide!
- 西安生物素-四聚乙二醇-酰胺-4苯酚 浅黄色半固态
猜你喜欢

7. type( )函数——查询数据类型

重估HR SaaS:一体化后的新三年

线程的同步与互斥

CAS:183896-00-6 (Biotin-PEG3-C3-NH2) PEG derivative

WPF DataGrid 使用数据模板

Leetcode83. 删除排序链表中的重复元素

Involved in PEG-Biotin (CAS: 1778736-18-7) Biotin-PEG4-OH is widely used in molecular target detection

PEG 衍生物Biotin-PEG1-OH(cas:95611-10-2,2-生物素氨基乙醇)优势说明

03|流程控制

openEuler 知:abi 检测
随机推荐
基于ABP的AppUser对象扩展
Kubernetes YAML编写 讲解
Today's sleep quality record 61 points
Kubernetes 开发环境比对
nfs配置
Redis 非关系型数据库学习(一) ---- Redis 的安装
const修饰指针的三种情况
【C语言】通讯录《静态内存版本》
Leetcode82. 删除排序链表中的重复元素 II
3.11-程序基本的控制语句 3.12-表达式 3.13-数据类型 3.14-常量/变量 3.15-标识符
ETCD快速入门-02 ETCD安装
MATLB|和她跌宕起伏最终到达人生之峰【浪漫旅途】
arm-4-裸板开发
c语言结构体、函数以及指针练习(简单通讯录)
When knowledge and action are one
hql语言
【obs】obsqsv11 硬编 及与metartc codec对比
Stanford CS143 速通PA1教程
Docker interview question 2--get the number of database connections and docker-compose
Enhanced Deep Residual Networks for Single Image Super-Resolution