![数据结构线性结构(二)6迷宫最短路径_第1张图片](http://img.e-com-net.com/image/info8/cd983efe04f74e8baa265d9268563edc.jpg)
![数据结构线性结构(二)6迷宫最短路径_第2张图片](http://img.e-com-net.com/image/info8/7e401fabb0494ff6bafdca0e4ef2c100.jpg)
#include
#include
using namespace std;
int dir[8][2]={{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};
int map_[1010][1010];
int sx,sy,ex,ey;
void BFS(int x,int y);
void outPath();
struct Node{
int x,y;
Node(int x=0,int y=0){
this->x=x;
this->y=y;
}
};
Node **path;
queue q;
int main()
{
int x,y;
cin>>x>>y;
sx=0;
sy=0;
ex=x-1;
ey=y-1;
path=new Node *[x];
for(int i=0;i>map_[i][j];
path[i][j]=Node(0,0);
}
}
BFS(sx,sy);
outPath();
return 0;
}
void BFS(int x,int y)
{
//queue> q;
q.push(Node(x,y));
while(!q.empty()) {
Node p=q.front();
q.pop();
if(p.x==ex&&p.y==ey) {
return;
}
for(int i=0;i<8;i++) {
int nx=p.x+dir[i][0];
int ny=p.y+dir[i][1];
if(nx<0||nx>=ex+1||ny<0||ny>=ey+1||map_[nx][ny]==1) {
continue;
}
path[nx][ny]=p;
q.push(Node(nx,ny));
map_[nx][ny]=1;
}
}
cout<