AcWing 6039. 地图探险
原题链接
简单
#include <iostream>
#include <cstring>
using namespace std;
typedef pair<int, int> PII;
const int N = 1010;
const PII direction[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
bool st[N][N];
char g[N][N];
int T, n, m, k, x, y, d;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> T;
while(T --){
cin >> n >> m >> k;
cin >> x >> y >> d;
memset(st, false, sizeof st);
st[x][y] = true;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> g[i][j];
int res = 1;
while(k --){
int dx = direction[d].first, dy = direction[d].second;
int tx = x + dx, ty = y + dy;
if(tx > 0 && tx <= n && ty > 0 && ty <= m && g[tx][ty] != 'x'){
x = tx;
y = ty;
if(!st[tx][ty]){
res ++;
st[tx][ty] = true;
}
}else d = (d + 1) % 4;
}
cout << res << endl;
}
return 0;
}