Ahws_rwhy @ 2024-10-26 15:14:34
#include <bits/stdc++.h>
using namespace std;
int t;
int n, m, k;
int x, y, d;
char mp[2001][2001];
int ans;
int main() {
cin >> t;
while (t--) {
ans = 0;
cin >> n >> m >> k;
cin >> x >> y >> d;
int nowx = x, nowy = y;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> mp[i][j];
}
}
while (k > 0) {
if (d == 0) {
k--;
nowx = nowx, nowy = nowy + 1;
if (nowy > m) {
d = (d + 1) % 4;
nowy = nowy - 1;
// continue;
}
if (mp[nowx][nowy] == '.' && d == 0) {
ans++;
}
if (mp[nowx][nowy] == 'x' && d == 0) {
d = (d + 1) % 4;
nowy = nowy - 1;
}
}
if (d == 1) {
k--;
nowx = nowx + 1, nowy = nowy;
if (nowx > n) {
d = (d + 1) % 4;
nowx = nowx - 1;
// continue;
}
if (mp[nowx][nowy] == '.' && d == 1) {
ans++;
}
if (mp[nowx][nowy] == 'x' && d == 1) {
d = (d + 1) % 4;
nowx = nowx - 1;
}
}
if (d == 2) {
k--;
nowx = nowx, nowy = nowy - 1;
if (nowy < 1) {
d = (d + 1) % 4;
nowy = nowy + 1;
// continue;
}
if (mp[nowx][nowy] == '.' && d == 2) {
ans++;
}
if (mp[nowx][nowy] == 'x' && d == 2) {
d = (d + 1) % 4;
nowy = nowy + 1;
}
}
if (d == 3) {
k--;
nowx = nowx - 1, nowy = nowy;
if (nowx < 1) {
d = (d + 1) % 4;
nowx = nowx + 1;
// continue;
}
if (mp[nowx][nowy] == '.' && d == 3) {
ans++;
}
if (mp[nowx][nowy] == 'x' && d == 3) {
// k--;
d = (d + 1) % 4;
nowx = nowx + 1;
}
}
}
cout << ans + 1 << endl;
}
return 0;
}
by MoMoNJ @ 2024-10-26 15:21:39
一个点可能重复走过多次
by YZHM @ 2024-10-26 15:32:49
标记走过的地方了没?
by Ahws_rwhy @ 2024-10-26 20:51:56
@MoMoNJ 谢!