是我对题目的理解有偏差吗?样例1的第一组数组算上了出发点(即 1,1),一共是经过三个空地。但是样例1的第二组数据没算上出发点,从1,2开始算共经过十三个空地,要算上1,1就经过14个空地。
#include <bits/stdc++.h>
using namespace std;
bool a[1010][1010];
int e[4] = {0, 1, 0, -1};
int v[4] = {1, 0, -1, 0};
int t, n, m, k, x, y, d, ans = 1;
char c;
bool check(int x_, int y_, int w){
if(a[x_+e[w]][y_+v[w]] == 0 && x_+e[w] <= n && x_+e[w] && y_+v[w] && y_+v[w] <= m) r1;
else r0;
}
void yd(int r){
if(check(x, y, d)){
switch(d){
case 0: y ++; break;
case 1: x ++; break;
case 2: y --; break;
case 3: x --; break;
}
ans ++;
}
else{
d = (d + 1) % 4;
}
}
int main(){
cin >> t;
while(t --){
cin >> n >> m >> k;
cin >> x >> y >> d;
ans = 1;
for(int i = 1; i <= n; ++ i){
for(int j = 1; j <= m; ++ j){
cin >> c;
if(c == 'x') a[i][j] = 1;
else a[i][j] = 0;
}
}
for(int i = 1; i <= k; ++ i) yd(1);
cout << ans;
}
return 0;
}