当前位置:网站首页>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<
}
边栏推荐
- 阿里云混合云管理平台多Region架构
- 有PEG-Biotin参与的(CAS:1778736-18-7)Biotin-PEG4-OH广泛用于分子靶点检测
- 你有对象类,我有结构体,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang结构体(struct)的使用EP06
- 温度响应性纳米水凝胶光子品体/纤维素修饰荧光水凝胶/载脂质体水凝胶的制备方法
- 考柏的感慨
- 二进制、八进制、十进制、十六进制之间的转换
- JVM内存和垃圾回收-10.直接内存
- 分形网络(FractalNet)----学习笔记
- dlopen failed: library “libtaml.so“ not found
- Tensor flow 踩坑记
猜你喜欢
随机推荐
Penetration Testing and Offensive and Defense Confrontation - Vulnerability Scanning & Logic Vulnerability (Part1)
How to activate the payment function on WeChat official account?
CAS:183896-00-6 (Biotin-PEG3-C3-NH2) PEG derivative
c语言指针练习题
错误提示:Syntax error on token “function”, delete this token
c语言结构体、函数以及指针练习(简单通讯录)
FITC标记生物素(FITC-生物素|CAS:134759-22-1)有哪些知识了?
CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源
手把手教你编写性能测试用例
C语言--数据的存储(上)
线程的同步与互斥
Project (7) - PolarSeg point cloud semantic segmentation
【猜凶手,猜名次,杨辉三角】经典小学奥数的代码逻辑是什么?
03|流程控制
How to turn off system protection in Win11?How to turn off the system protection restore function?
LSTM-based distributed energy generation prediction (Matlab code implementation)
Leetcode82. 删除排序链表中的重复元素 II
Docker 面试题2则--取数据库连接数和docker-compose
-向量点积-
Redis 非关系型数据库学习(一) ---- Redis 的安装