本题主要考察:模拟法
注意多组数据
C++ 代码
#include <bits/stdc++.h>
using namespace std;
int T, n, m, x, y, d, k, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
string s[1010];
bool b[1010][1010];
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d%d%d%d%d%d", &n, &m, &k, &x, &y, &d);
for (int i = 1; i <= n; i++) cin >> s[i], s[i] = " " + s[i];
memset(b, 0, sizeof b);
int ans = 0;
b[x][y] = 1;
while (k--)
{
int x1 = x + dx[d], y1 = y + dy[d];
if (x1 < 1 || x1 > n || y1 < 1 || y1 > m || s[x1][y1] == 'x') d = (d + 1) % 4;
else x = x1, y = y1, b[x][y] = 1;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) if (b[i][j]) ans++;
printf("%d\n", ans);
}
return 0;
}