# 迷宫问题 （BFS）

```int maze[5][5] = {

0, 1, 0, 0, 0,

0, 1, 0, 1, 0,

0, 0, 0, 0, 0,

0, 1, 1, 1, 0,

0, 0, 0, 1, 0,

};```

Input

Output

Sample Input

```0 1 0 0 0
0 1 0 1 0
0 0 0 0 0
0 1 1 1 0
0 0 0 1 0```

Sample Output

```(0, 0)
(1, 0)
(2, 0)
(2, 1)
(2, 2)
(2, 3)
(2, 4)
(3, 4)
(4, 4)```
``````#include<iostream>
#include<cmath>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
struct node{
int x,y;
int pre;
}nodes[36];
int Map[6][6];
int vis[6][6]={0};
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
{
{
return ;
}
}
void bfs(int x,int y)
{
int tail = 1;
nodes[0].x = 0;
nodes[0].y = 0;
nodes[0].pre = -1;

struct node New;
{
{
return ;
}
for(int i = 0;i<4;i++)
{
if(New.x>=0&&New.x<=4&&New.y>=0&&New.y<=4)
{
if(!vis[New.x][New.y]&&!Map[New.x][New.y])
{
vis[New.x][New.y] = 1;
nodes[tail++] = New;
}
}
}
}
}
int main(){
for(int i = 0;i<5;i++)
{
for(int j = 0;j<5;j++)
{
scanf("%d",&Map[i][j]);
}
}
printf("(0, 0)\n");
bfs(0,0);
return 0;
}
``````

原文作者：BFS
原文地址: https://blog.csdn.net/weixin_41988545/article/details/82968172
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。