yongxvcheng @ 2024-10-27 15:30:09
#include<cstdio>
int fx(int x,int d){
if(d==1) return(x+1);
else if(d==3) return(x-1);
else return x;
}
int fy(int y,int d){
if(d==0) return(y+1);
else if(d==2) return(y-1);
else return y;
}
int main(){
int m,n,t,k,x,y,d,ans=0;
char p;
scanf("%d",&t);
for(int i=0;i<t;i++){
scanf("%d",&n);
scanf("%d",&m);
int arr[n][m]={0};
scanf("%d",&k);
scanf("%d",&x);
scanf("%d",&y);
scanf("%d",&d);
x--;
y--;
for(int j=0;j<n;j++){
for(int q=0;q<m;q++){
scanf("%c",&p);
if(p=='\n'){
q-=1;
continue;
}
if(p=='x') arr[j][q]=-1;
}
}
for(int j=0;j<k;j++){
if(arr[x][y]==0){
ans++;
arr[x][y]++;
}
if(fx(x,d)<0 or fy(y,d)<0 or fy(y,d)>=m or fx(x,d)>=n){
d=(d+1)%4;
continue;
}
if(arr[fx(x,d)][fy(y,d)]==-1){
d=(d+1)%4;
continue;
}
x=fx(x,d);
y=fy(y,d);
if(arr[x][y]==0){
ans++;
arr[x][y]++;
}
}
printf("%d\n",ans);
}
}
by sdjjdjdjdjd @ 2024-10-27 15:35:57
尝试将数据读入改为:
for(int j=0;j<n;j++){
for(int q=0;q<m;q++){
scanf("%c",&p);
if(p=='x') arr[j][q]=-1;
}
getchar();//用于过滤换行
}