走迷宫
![img](https://img-blog.csdnimg.cn/20201118221630766.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1Bob2VuaXhfWmVuZ0hhbw==,size_16,color_FFFFFF,t_70#pic_center)
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=20+50;
int n,m,sx,sy,tx,ty,a[maxn][maxn],vis[maxn][maxn],d[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct Node{
int x,y;
};
int main(){
int i,j;
cin>>n>>m>>sx>>sy>>tx>>ty;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
cin>>a[i][j];
}
}
queue<Node>q;
Node now;now.x=sx;now.y=sy;
q.push(now);
while(!q.empty()){
now=q.front();q.pop();
if(vis[now.x][now.y])continue ;
vis[now.x][now.y]=1;
for(i=0;i<4;i++){
Node nex;nex.x=now.x+d[i][0];nex.y=now.y+d[i][1];
if(nex.x>=0&&nex.x<=n-1&&nex.y>=0&&nex.y<=m-1&&!a[nex.x][nex.y])q.push(nex);
}
}
if(vis[tx][ty])cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}