zzjjack @ 2024-11-09 11:02:39
#include<bits/stdc++.h>
using namespace std;
int t;
char mp[6][1001][1001];
bool wmp[6][1001][1001];
int n, m, k, ans[6] = {0, 1, 1, 1, 1, 1};
int v[2][4] = {
0, 1, 0, -1,
1, 0, -1, 0
};
bool inMap(int y, int x)
{
return y >= 1 && y <= n && x >= 1 && x <= m;
}
void walk(int y, int x, int d, int w, int i)
{
w++;
if(w > k)
return;
int posY = y + v[0][d];
int posX = x + v[1][d];
if(inMap(y, x) && mp[i][posY][posX] == '.')
{
if(!wmp[i][posY][posX])ans[i]++;
wmp[i][posY][posX] = 1;
walk(posY, posX, d, w, i);
}
else walk(y, x, (d + 1) % 4, w, i);
}
int main()
{
cin >> t;
for(int i = 1; i <= t; i++)
{
int y, x, d;
cin >> n >> m >> k;
cin >> y >> x >> d;
for(int j = 1; j <= n; j++)
for(int k = 1; k <= m; k++)
cin >> mp[i][j][k];
walk(y, x, d, 0, i);
}
for(int i = 1; i <= t; i++)
cout << ans[i] << endl;
return 0;
}