1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| #include <bits/stdc++.h> using namespace std;
int T; int n, m, k; int x, y, d; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0};
int main() { cin >> T; while (T--) { cin >> n >> m >> k; cin >> x >> y >> d; x--, y--;
char mp[1005][1005]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> mp[i][j]; } bool vis[1005][1005]; memset(vis, 0, sizeof(vis));
int moves = 0, cnt = 0; if (mp[x][y] == '.' && !vis[x][y]) { vis[x][y] = true; cnt++; } while (moves < k) { int nx = x + dx[d]; int ny = y + dy[d]; if (nx >= 0 && nx < n && ny >= 0 && ny < m && mp[nx][ny] == '.') { x = nx; y = ny; if (!vis[x][y]) { vis[x][y] = true; cnt++; } } else d = (d + 1) % 4; moves++; }
cout << cnt << "\n"; } return 0; }
|