QZWWW @ 2024-11-02 19:00:37
2024-CSP-J-2 为啥本代码跑了后RE 本地运行可以过
by QZWWW @ 2024-11-02 19:02:53
#include<bits/stdc++.h>
using namespace std;
int t,n,m,k;
int x,y,d;
char mp[1010][1010];
char vis[1010][1010];
int tx[10] = {0,1,0,-1};
int ty[10] = {1,0,-1,0};
int dfs(int x,int y ,int d,int step,int cnt)
{
if(step==k)
{
cout<<cnt<<endl;
return 0;
}
int dx = x + tx[d];int dy = y + ty[d];
if(dx > 0 && dy > 0 && dx <= n && dy <= m && mp[dx][dy]!='x' )
{
if(vis[dx][dy]==1)
{
vis[dx][dy]=1;
dfs(dx,dy,d,step+1,cnt);
}
else{
vis[dx][dy]=1;
dfs(dx,dy,d,step+1,cnt+1);
}
}
else
{
dfs(x,y,(d+1)%4,step+1,cnt);
}
}
int main()
{
cin>>t;
int step;
int cnt;
while(t--)
{
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>mp[i][j];
}
}
memset(vis,0,sizeof(vis));
vis[x][y] = 1;
dfs(x,y,d,0,1);
}
return 0;
}