0
已解决
张恩泽
高级天翼
高级天翼
//CODE
//#pragma GCC optimize(3)
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
using namespace std;
int n, a, b, c, d;
string s;
bool G[10][10];
bool vis[10][10];
bool flag = false;
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
void dfs(int x, int y) {
if (x == c && y == d) {
flag = true;
return ;
}
for (int i = 0; i < 4; i ++) {
int nx = x + dir[i][0], ny = y + dir[i][1];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= n && G[nx][ny] && !vis[nx][ny]) {
vis[nx][ny] = true;
dfs(nx, ny);
vis[nx][ny] = false;
}
}
}
int main() {
// freopen ("题目名.in", "r", stdin);
// freopen ("题目名.out", "w", stdout);
int k;
cin >> k;
for (int i = 1; i <= k ;i ++) {
cin >> n;
for (int j = 1; j <= n; j ++) {
cin >> s;
for (int k = 0; k < s.size(); k ++) {
if (s[j] == 's') {
G[j][k + 1] = true;
}
}
}
cin >> a >> b >> c >> d;
vis[a][b] = true;
dfs(a, b);
vis[a][b] = false;
if (flag == true) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
// fclose (stdin);
// fclose (stdout);
return 0;//好习惯!
}
张恩泽在2021-05-04 23:04:34追加了内容
顶!
张恩泽在2021-05-05 14:45:01追加了内容
//CODE
//#pragma GCC optimize(3)
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n, a, b, c, d;
string s;
bool G[10][10];
bool vis[10][10];
bool flag = false;
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
void dfs(int x, int y) {
if (flag == true) {
return ;
}
if (x == c && y == d) {
flag = true;
return ;
}
for (int i = 0; i < 4; i ++) {
int nx = x + dir[i][0], ny = y + dir[i][1];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= n && G[nx][ny] && !vis[nx][ny]) {
vis[nx][ny] = true;
dfs(nx, ny);
vis[nx][ny] = false;
}
}
}
int main() {
// freopen ("题目名.in", "r", stdin);
// freopen ("题目名.out", "w", stdout);
int k;
cin >> k;
for (int i = 1; i <= k ;i ++) {
cin >> n;
for (int j = 1; j <= n; j ++) {
cin >> s;
for (int k = 0; k < s.size(); k ++) {
if (s[j] == 's') {
G[j][k + 1] = true;
}
}
}
cin >> a >> b >> c >> d;
vis[a][b] = true;
dfs(a, b);
vis[a][b] = false;
if (flag == true) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
flag = false;
memset(vis, false, sizeof(vis));
memset(G, false, sizeof(G));
}
// fclose (stdin);
// fclose (stdout);
return 0;//好习惯!
}