destiny_w @ 2024-10-26 17:13:22
#include<bits/stdc++.h>
using namespace std;
int n,m,k,x,y,d;
const int N=1e3+50;
int a[N][N];
int vis[N][N];
int f(int x0,int y0){
if(x0<1 || x0>n ||y0<1 || y0>m || a[x0][y0]==0){
return 0;
}
return 1;
}
int main(){
int t;
cin>>t;
while(t--){
cin>>n>>m>>k>>x>>y>>d;
vis[x][y]=1;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
char c;
cin>>c;
if(c=='x') a[i][j]=0;
else a[i][j]=1;
}
}
for(int i=1;i<=k;++i){
if(d==0){
int tmp=f(x,y+1);
if(tmp==1){
y+=1;
vis[x][y]=1;
}
else{
d=(d+1)%4;
}
}
else if(d==1){
int tmp=f(x+1,y);
if(tmp==1){
x+=1;
vis[x][y]=1;
}
else{
d=(d+1)%4;
}
}
else if(d==2){
int tmp=f(x,y-1);
if(tmp==1){
y-=1;
vis[x][y]=1;
}
else{
d=(d+1)%4;
}
}
else if(d==3){
int tmp=f(x-1,y);
if(tmp==1){
x-=1;
vis[x][y]=1;
}
else{
d=(d+1)%4;
}
}
}
int index=0;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(vis[i][j]==1){
index ++;
}
}
}
cout<<index<<endl;
}
return 0;
}
by moziqian @ 2024-10-26 17:21:17
你忘记初始化
你可以在输入语句下方加上这句话
v[i][j]=0;
by moziqian @ 2024-10-26 17:27:53
@destiny_w
by destiny_w @ 2024-10-26 18:27:17
哦哦哦,改了改了,AC
by destiny_w @ 2024-10-26 18:28:12
虚惊一场