X_tiger @ 2024-10-26 15:31:59
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 3;
int f[N][N];
int t[N][N];
int a1,a2;
signed main(){
int T;
cin >> T;
while ( T -- ){
int n,m,k;
cin >> n >> m >> k;
int x,y,d;
cin >> x >> y >> d;
a1 = x;
a2 = y;
char s;
for ( int i = 1; i <= n; i ++ ){
for ( int j = 1; j <= m; j ++ ){
cin >> s;
if ( s == 'x' ){
f[i][j] = -1;
}
else{
f[i][j] = 1;
}
}
}
for ( int i = 1; i <= k; i ++ ){
int xx = x,yy = y;
if ( d == 0 ) yy ++;
if ( d == 1 ) xx ++;
if ( d == 2 ) yy --;
if ( d == 3 ) xx --;
int fl = 0;
if ( 1 <= xx && xx <= n && 1 <= yy && y <= m ){
if ( f[xx][yy] == 1 ){
x = xx;
y = yy;
t[xx][yy] = 1;
fl = 1;
}
}
if ( fl == 0 ){
d = ( d + 1 ) % 4;
}
}
int cnt = 0;
for ( int i = 1; i <= n; i ++ ){
for ( int j = 1; j <= m; j ++ ){
if ( t[i][j] == 1 ){
cnt ++;
}
}
}
if ( t[a1][a2] == 1 ){
cout << cnt << "\n";
}
else{
cout << cnt + 1 << "\n";
}
}
}
by Wuyuetongzhou @ 2024-10-26 15:44:02
if ( 1 <= xx && xx <= n && 1 <= yy && y <= m ){
改成
if ( 1 <= xx && xx <= n && 1 <= yy && yy <= m ){
还要初始化
by X_tiger @ 2024-10-29 14:23:29
@Wuyuetongzhou 谢谢
by X_tiger @ 2024-12-14 08:40:12
@X_tiger好吧写错了考场代码