qujunhao @ 2024-10-26 14:42:04
求解
by Loyal_Soldier @ 2024-10-26 14:44:08
我用dfs
AC了
by qujunhao @ 2024-10-26 14:46:54
@huangkaikai o
by qujunhao @ 2024-10-26 14:48:04
@huangkaikai 求代码
by Gavinzhou @ 2024-10-26 15:56:42
@qujunhao
#include<iostream>
using namespace std;
int n,m;
char a[1005][1005];
bool ans[1005][1005];
void f(int x,int y,int d,int k){
ans[x][y]=true;
if(k==0) return;
int nx=x,ny=y;
if(d==0) ny++;
else if(d==1) nx++;
else if(d==2) ny--;
else nx--;
if(nx<1||ny<1||nx>n||ny>m||a[nx][ny]!='.') f(x,y,(d+1)%4,k-1);
else f(nx,ny,d,k-1);
}
int main(){
int t;
cin>>t;
while(t--){
for(int i=1;i<=1000;i++){
for(int j=1;j<=1000;j++){
ans[i][j]=false;
}
}
int k,x,y,d;
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
int cnt=0;
f(x,y,d,k);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(ans[i][j]) cnt++;
}
}
cout<<cnt<<endl;
}
return 0;
}
我的
by qujunhao @ 2024-10-26 17:45:20
@Gavinzhou 谢谢
by Gavinzhou @ 2024-10-27 07:41:48
@qujunhao 求关