chenzhaosheng @ 2024-11-17 14:54:13
#include<bits/stdc++.h>
using namespace std;
int n,m,k,x,y,d;
int T;
char arr[1005][1005];
bool vis[1005][1005];
int main(){
cin>>T;
while(T--){
int cnt=1;
cin>>n>>m>>k;
cin>>x>>y>>d;
vis[x][y] = 1;
for(int j=1;j<=n;j++){
for(int q=1;q<=m;q++){
cin>>arr[j][q];
}
}
memset(vis,0,sizeof(vis));
while(k--){
if(d==0){
if((x>=1&&x<=n)&&(y+1>=1&&y+1<=m)&&(arr[x][y+1]=='.')){
y+=1;
if(vis[x][y]==0){
cnt++;
vis[x][y]=1;
}
}else{
d=(d+1)%4;
}
}
else if(d==1){
if((x+1>=1&&x+1<=n)&&(y>=1&&y<=m)&&(arr[x+1][y]=='.')){
x+=1;
if(vis[x][y]==0){
cnt++;
vis[x][y]=1;
}
}else{
d=(d+1)%4;
}
}
else if(d==2){
if((x>=1&&x<=n)&&(y-1>=1&&y-1<=m)&&(arr[x][y-1]=='.')){
y-=1;
if(vis[x][y]==0){
cnt++;
vis[x][y]=1;
}
}else{
d=(d+1)%4;
}
}
else if(d==3){
if((x-1>=1&&x-1<=n)&&(y>=1&&y<=m)&&(arr[x-1][y]=='.')){
x-=1;
if(vis[x][y]==0){
cnt++;
vis[x][y]=1;
}
}else{
d=(d+1)%4;
}
}
}
cout<<cnt<<endl;
}
return 0;
}
by yise @ 2024-11-25 20:03:32
@chenzhaosheng 你置0将x和y也重置了