0
已解决
张国鉴
资深守护
资深守护
#include<iostream>
#include<queue>
using namespace std;
const int dir[4][2]{
{-1,0},{0,-1},{1,0},{0,1}
};
struct coord{
int x,y;
};
int N,m;
int a,b,c,d;
queue<coord>q;
char p[110][110];
bool can(int x,int y){
if (x>=1&&x<=m&&y>=1&&y<=m) return true;
return false;
}
bool bfs(int x,int y,int z,int w){
if (p[x][y]=='d'||p[z][w]=='d') return false;
q.push((coord){x,y});
while(!q.empty()){
coord now=q.front();
q.pop();
if (now.x==z&&now.y==w) return true;
for (int i=0;i<4;i++){
int nx=now.x+dir[i][0];
int ny=now.y+dir[i][1];
if (p[nx][ny]=='s'&&can(nx,ny)){
q.push((coord){nx,ny});
}
}
}
return false;
}
int main(){
cin>>N;
for (int i=1;i<=N;i++){
cin>>m;
for (int j=1;j<=m;j++){
for (int k=1;k<=m;k++){
cin>>p[j][k];
}
}
cin>>a>>b>>c>>d;
if (bfs(a,b,c,d)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}