#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
int main()
{
int A[7][7];
int u;
int fa[7][7]={
{0}};
int record[7][7]={
{0}};
queue<int> q;
int i,j;
for (i=0;i<=4;i++)
for (j=0;j<=4;j++)
cin >> A[i][j];
u=0;
q.push(u);
record[0][0]=1;
while (q.front()!=24 && !q.empty())
{
int x=q.front()/5;
int y=q.front()%5;
if (!record[x+1][y] && x+1<=4 && A[x+1][y]!=1)
{
u=(x+1)*5+y;
fa[x+1][y]=q.front();
q.push(u);
record[x+1][y]=1;
}
if (!record[x-1][y] && x-1>=0 && A[x-1][y]!=1)
{
u=(x-1)*5+y;
fa[x-1][y]=q.front();
q.push(u);
record[x-1][y]=1;
}
poj3984(广搜走迷宫输出路径)
最新推荐文章于 2022-12-05 18:33:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)