wry0510 @ 2024-11-09 18:27:39
#include<bits/stdc++.h>
using namespace std;
int t,n,m,k,stx,sty,d1,b[1005][1005],ans;
char a[10005][10005];
int main(){
cin>>t;
while(t--){
memset(b,0,sizeof(b));
cin>>n>>m>>k>>stx>>sty>>d1;
b[stx][sty]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
while(k--){
if(d1==0){
int ny=sty+1;
if(stx>=1&&stx<=n&&ny>=1&&ny<=m&&a[stx][ny]=='.'){
sty=sty+1;
b[stx][sty]=1;
}
else d1=(d1+1)%4;
}
else if(d1==1){
int nx=stx+1;
if(nx>=1&&nx<=n&&sty>=1&&sty<=m&&a[nx][sty]=='.'){
stx=stx+1;
b[stx][sty]=1;
}
else d1=(d1+1)%4;
}
else if(d1==2){
int nx=sty-1;
if(nx>=1&&nx<=n&&sty>=1&&sty<=m&&a[nx][sty]=='.'){
sty=sty-1;
b[stx][sty]=1;
}
else d1=(d1+1)%4;
}
else if(d1==3){
int ny=stx-1;
if(ny>=1&&ny<=n&&stx>=1&&stx<=m&&a[stx][ny]=='.'){
stx=stx-1;
b[stx][sty]=1;
}
else d1=(d1+1)%4;
}
}
for(int i=1;i<=n;i++){
for(int j=i;j<=m;j++){
if(b[i][j]==1)ans++;
}
}
cout<<ans<<"\n";
}
}
by iranai @ 2024-11-09 18:47:50
@wry0510 你的d1==2和d1==3的情况nx,ny,stx,sty意义是不是搞错了
by wry0510 @ 2024-11-09 18:54:29
好的、
@iranai