rq_hyj @ 2024-10-28 18:41:44
WA在第7、8个点
#include<cstdio>
#include<iostream>
using namespace std;
int len;
int n,m,ste;
int x,y,k;
char arr[1005][1005];
int t[1005][1005];
int ans;
void ddxyz() {
for(int i=0; i<=1000; i++) {
for(int j=0; j<=1000; j++) {
t[i][j]=0;
}
}
ans=0;
}
int main() {
cin>>len;
while(len--) {
cin>>n>>m>>ste>>x>>y>>k;
ddxyz();
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
cin>>arr[i][j];
}
}
x--;
y--;
ans=1;
t[x][y]=1;
for(int i=1; i<=ste; i++) {
if(k==0) {
if(y+1<m&&arr[x][y+1]=='.') {
y++;
} else {
k=1;
}
} else if(k==1) {
if(x+1<m&&arr[x+1][y]=='.') {
x++;
} else {
k=2;
}
} else if(k==2) {
if(y-1>=0&&arr[x][y-1]=='.') {
y--;
} else {
k=3;
}
} else {
if(x-1>=0&&arr[x-1][y]=='.') {
x--;
} else {
k=0;
}
}
if(t[x][y]==0) {
ans++;
t[x][y]=1;
}
}
printf("%d\n",ans);
}
return 0;
}
by rq_hyj @ 2024-10-28 18:46:02
代码有点丑,大佬们勿喷
by cpp_xhq @ 2024-10-28 18:52:09
来听一听!
大模拟要注意细节!
请看这里:
if(x+1<m&&arr[x+1][y]=='.') {
x++;
} else {
k=2;
}
by cpp_xhq @ 2024-10-28 18:53:04
@cpp_xhq 已经A了
by cpp_xhq @ 2024-10-28 18:53:51
@cpp_xhq
求关!!!
by rq_hyj @ 2024-10-28 19:01:34
@cpp_xhq 谢谢大佬