迷宫题解
2025-07-25 17:34:22
发布于:浙江
#include <bits/stdc++.h>
using namespace std;
int dr[][2]={0,1,1,0,0,-1,-1,0},n,m,t,sx,sy,fx,fy,cnt=0;
char dt[45][45];
void dfs(int x,int y){
dt[x][y]='#';
if(x==fx&&y==fy){
return;
}
for(int i = 0;i < 4;i++){
int drx=x+dr[i][0],dry=y+dr[i][1];
if(drx>=1&&drx<=n&&dry>=1&&dry<=m&&dt[drx][dry]!='#'){
dfs(drx,dry);
}
}
}
int main(){
cin>>n>>m;
cin>>sx>>sy>>fx>>fy;
for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++)cin>>dt[i][j];
dfs(sx,sy);
cout<<(dt[fx][fy]=='#'?"YES":"NO");
return 0;
}
这里空空如也
有帮助,赞一个