cqy12345678 @ 2024-10-26 21:40:35
#include<bits/stdc++.h>
using namespace std;
int t;
int n,m,k;
int x,y,d;
char a[1005][1005];
bool vis[1005][1005];
int ans=0;
int main(){
cin>>t;
for(int xx=1;xx<=t;xx++){
cin>>n>>m>>k;
cin>>x>>y>>d;
ans=0;
memset(vis,false,sizeof(vis));
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=k;i++){
if(d==0){
int xx=x;
int yy=y+1;
if(xx<=n&&xx>=1&&yy<=m&&yy>=1){
vis[xx][yy]=true;
x=xx;
y=yy;
}
else{
d=(d+1)%4;
}
}
if(d==1){
int xx=x+1;
int yy=y;
if(xx<=n&&xx>=1&&yy<=m&&yy>=1){
vis[xx][yy]=true;
x=xx;
y=yy;
}
else{
d=(d+1)%4;
}
}
if(d==2){
int xx=x;
int yy=y-1;
if(xx<=n&&xx>=1&&yy<=m&&yy>=1){
vis[xx][yy]=true;
x=xx;
y=yy;
}
else{
d=(d+1)%4;
}
}
if(d==3){
int xx=x-1;
int yy=y;
if(xx<=n&&xx>=1&&yy<=m&&yy>=1){
vis[xx][yy]=true;
x=xx;
y=yy;
}
else{
d=(d+1)%4;
}
}
}
for(int i=1;i<=n;i++){
if(vis[i]){
ans++;
}
}
cout<<ans+1<<endl;
}
return 0;
}
by moziqian @ 2024-10-26 21:43:29
你没有判断下一步走到的格子是不是空地。