题目链接:
http://47.110.135.197/problem.php?id=4261
AC代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 500001
struct Point{ //节点
int x;
int y;
Point(int x,int y):x(x),y(y){
}
Point(){
}
};
int matrix[5][5];//存储原始迷宫
bool visit[5][5];//访问标记
Point path[5][5];//存储前驱节点
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};//方向
bool Judge(int x,int y){ //判断是否在迷宫内
if(x>=0&&x<5&&y>=0&&y<5){
return true;
}
return false;
}
void bfs(){
Point start=Point(0,0);
visit[0][0]=true;
queue<Point> Q; //节点队列
Q.push(start);
while(!Q.empty()){
Point u=Q.front(); //获取当前队首节点
Q.pop();
int x=u.x;
int y=u.y;
if(x==4&&y==4){
return;
}
for(int i=0;i<4;i++){
int next_x=x+dx