代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int t;
int n,m,k;
int x,y,c;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
char a[N][N];
bool vis[N][N];
int ans;
int main(){
cin >> t;
while(t--){
ans=1;
memset(vis,0,sizeof(vis));
cin >> n >> m >> k;
cin >> x >> y >> c;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
vis[x][y]=1;
while(k--){
if(x+dx[c]<1||x+dx[c]>n||y+dy[c]<1||y+dy[c]>m||a[x+dx[c]][y+dy[c]]=='x'){
c=(c+1)%4;
}else{
x+=dx[c];
y+=dy[c];
if(vis[x][y]!=1){
ans++;
vis[x][y]=1;
}
}
}
cout << ans << endl;
}
return 0;
}