xuanhongye @ 2024-11-06 13:51:52
纯模拟 为什么只过了四个测试点
#include <bits/stdc++.h>
using namespace std;
char a[2005][2005];
bool vis[2005][2005];
int ans;
int x,y,d;
int n,m,k;
int main(){
int t;
cin >> t;
while(t--){
cin >> n >> m >> k;
cin >> x >> y >> d;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
memset(vis,false,sizeof(vis));
while(k){
if (d == 0 && k){
if (vis[x][y] == 0){
ans++;
vis[x][y] = 1;
}
y += 1;
if (a[x][y] == 'x' || y > m) {k--;d = (d + 1) % 4; y -= 1;}
else{
if (vis[x][y] == 0){
ans++;
k--;
vis[x][y] = 1;
}
}
}
if (d == 1 && k){
if (vis[x][y] == 0){
ans++;
vis[x][y] = 1;
}
x += 1;
if (a[x][y] == 'x' || x > n) {k--;d = (d + 1) % 4; x -= 1;}
else{
if (vis[x][y] == 0){
ans++;
k--;
vis[x][y] = 1;
}
}
}
if (d == 2 && k){
if (vis[x][y] == 0){
ans++;
vis[x][y] = 1;
}
y -= 1;
if (a[x][y] == 'x' || y <= 0) {k--;d = (d + 1) % 4; y += 1;}
else{
if (vis[x][y] == 0){
ans++;
k--;
vis[x][y] = 1;
}
}
}
if (d == 3 && k){
if (vis[x][y] == 0){
ans++;
vis[x][y] = 1;
}
x -= 1;
if (a[x][y] == 'x' || x <= 0) {k--;d = (d + 1) % 4; x += 1;}
else{
if (vis[x][y] == 0){
ans++;
k--;
vis[x][y] = 1;
}
}
}
}
cout << ans << '\n';
ans = 0;
}
return 0;
}