题解
2024-03-24 19:11:09
发布于:江苏
12阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int N=42;
int n,m,sx,sy,fx,fy,cnt=0;
bool flag;
int mp[N][N];
int dir[4][2]={0,1,1,0,
0,-1,-1,0};
char maze[N][N];
bool vis[N][N];
void dfs(int x,int y){
if(x==fx&&y==fy){
flag=true;
return;
}
vis[x][y]=true;
for (int i=0;i<4;i++){
int nx=x+dir[i][0];
int ny=y+dir[i][1];
if (nx<=0||ny<=0||nx>n||ny>m){
continue;
}
if(!vis[nx][ny]&&maze[nx][ny]=='.'){
dfs(nx,ny);
}
}
}
int main(){
cin>>n>>m>>sx>>sy>>fx>>fy;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>maze[i][j];
}
}
dfs(sx,sy);
if(flag){
cout<<"YES";
}else{
cout<<"NO";
}
return 0;
}
这里空空如也
有帮助,赞一个