SnowZ @ 2024-10-27 12:04:10
#include <bits/stdc++.h>
using namespace std;
int T;
int n, m, k;
int sx, sy, sd;
int ans = 0, cnt = 0;
bool st[1020][1020];
char dt[1020][1020];
void move(int cnt, int d, int x, int y)
{
if(cnt > k)
{
printf("%d\n",ans);
ans = 0;
return;
}
int nextStep[4][2] = {
{x, y+1},
{x+1, y},
{x, y-1},
{x-1, y},
};
int nx = nextStep[d][0], ny = nextStep[d][1];
if(st[nx][ny] == false || nx < 1 || nx > n || ny < 1 || ny > m || dt[nx][ny] == 'x')
{
d = (d+1) % 4;
}
else
{
if(st[nx][ny])
{
x = nx;
y = ny;
ans++;
}
}
move(cnt+1, d, x, y);
}
int main()
{
cin >> T;
for(int ti = 0; ti < T; ti++)
{
cin >> n >> m >> k;
cin >> sx >> sy >> sd;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
cin >> dt[i][j];
if(dt[i][j] == '.')
{
st[i][j] = true;
}
else st[i][j] = false;
}
}
move(0, sd, sx, sy);
}
return 0;
}