![](https://img-blog.csdnimg.cn/direct/cba29eaf30bf471b96cd262de8d8db31.png)
![](https://img-blog.csdnimg.cn/direct/5f66d31064b94ac585dac40c34327c1d.png)
![](https://img-blog.csdnimg.cn/direct/58777d8fc255449fb82b350c081dec0f.png)
![](https://img-blog.csdnimg.cn/direct/3a7caa2b0d174eaf9547c41d9d9b492f.png)
【C++代码】
#include <iostream>
using namespace std;
char maze[15][10];
int sx, sy;
int dir[8][2] = {{2, 1}, {2, -1}, {1, 2}, {1, -2}, {-2, 1}, {-2, -1}, {-1, 2}, {-1, -2}};
bool vis[15][10];
bool check(int x,int y){
if((x>=1&&y>=1&&x<=10&&y<=9)&&!vis[x][y]&&maze[x][y]!='#'){
return true;
}
return false;
}
bool dfs(int x,int y){
if(maze[x][y]=='T'){
return true;
}
vis[x][y] = true;
for(int i=0;i<8;i++){
int tx=x+dir[i][0];
int ty=y+dir[i][1];
if(check(tx,ty)){
if(dfs(tx,ty)){
return true;
}
}
}
return false;
}
int main() {
freopen("chess.in","r",stdin);
freopen("chess.out","w",stdout);
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 9; j++) {
cin>>maze[i][j];
if(maze[i][j]=='S'){
sx=i;sy=j;
}
}
}
if(dfs(sx,sy)){
cout<<"Yes"<<endl;
}
else {
cout<<"No"<<endl;
}
return 0;
}