liziao791219 @ 2024-10-30 21:50:26
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t,n,m,k,x,y,d;
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>m>>k>>x>>y>>d;
char s[n+5][m+5];
int ss[n+5][m+5]={};
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>s[i][j];
}
}
int ans=1;
ss[x][y]=1;
while(k--){
if(d==0){
if(s[x][y+1]=='.'){
if(ss[x][y+1]==0){
ans++;
ss[x][y+1]=1;
}
y++;
printf("(%d,%d) %d %d\n",x,y,k,ans);
continue;
}
else{
printf("东-->南 %d %d\n",k,ans);
d++;
continue;
}
}
if(d==1){
if(s[x+1][y]=='.'){
if(ss[x+1][y]==0){
ans++;
ss[x+1][y]=1;
}
x++;
printf("(%d,%d) %d %d\n",x,y,k,ans);
continue;
}
else{
printf("南-->西 %d %d\n",k,ans);
d++;
continue;
}
}
if(d==2){
if(s[x][y-1]=='.'){
if(ss[x][y-1]==0){
ans++;
ss[x][y-1]=1;
}
y--;
printf("(%d,%d) %d %d\n",x,y,k,ans);
continue;
}
else{
printf("西-->北 %d %d\n",k,ans);
d++;
continue;
}
}
if(d==3){
if(s[x-1][y]=='.'){
if(ss[x-1][y]==0){
ans++;
ss[x-1][y]=1;
}
x--;
printf("(%d,%d) %d %d\n",x,y,k,ans);
continue;
}
else{
printf("北-->东 %d %d\n",k,ans);
d=0;
continue;
}
}
}
cout<<ans<<endl;
}
return 0;
}
by liziao791219 @ 2024-10-30 21:54:49
printf 测试用的请无视
by dpvis2025liu @ 2024-10-31 17:01:59
判断边界 x>=1&&x<=n&&y+1>=1&&y+1<=m x+1>=1&&x+1<=n&&y>=1&&y<=m x>=1&&x<=n&&y-1>=1&&y-1<=m x-1>=1&&x-1<=n&&y>=1&&y<=m
by dpvis2025liu @ 2024-10-31 17:03:16
ss数组更新