LynnLake @ 2024-11-26 20:01:10
#include<iostream>
#include<cstring>
using namespace std;
struct nood
{
int k, n, m, x, y, d;
};
const int maxsize = 1001 * 1001;
char map[1001][1001];
bool visitmap[1001][1001];
int mx[4] = {0, 1, 0, -1}, my[4] = {1, 0, -1, 0};
int movetimes(nood* node)
{
int cnt = 1;
int tmp = node -> k;
while(tmp--)
{
int x1 = node -> x + mx[node -> d], y1 = node -> y + my[node -> d];
if(x1 < 1 || x1 > node -> n)
{
node -> d += 1;
node -> d %= 4;
continue;
}
if(y1 > node -> m || y1 < 1)
{
node -> d += 1;
node -> d %= 4;
continue;
}
if(map[x1][y1] == 'x')
{
node -> d += 1;
node -> d %= 4;
continue;
}
if(visitmap[x1][y1])
{
continue;
}
node -> x = x1, node -> y = y1;
visitmap[x1][y1] = true;
cnt++;
//cout << node -> d << ' ' << visitmap[x1][y1] << ' ' << map[x1][y1] << ' ' << x1 << ' ' << y1 << endl;
}
return cnt;
}
int main()
{
int t;
cin>>t;
nood node;
int n, m, k, x, y, d;
while(t--)
{
memset(visitmap, 0, maxsize);
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
cin>>map[i][j];
}
}
node.d = d;
node.k = k;
node.n = n;
node.m = m;
node.x = x;
node.y = y;
int ans = movetimes(&node);
cout << ans << endl;
}
return 0;
}