lihans @ 2024-04-03 19:48:26
萌新求调qaq
#include <bits/stdc++.h>
using namespace std;
char mp[105][105];
bool dfs(int,int);
int n,m;
int vis(int x,int y)
{
mp[x][y]='0';
dfs(x,y);
}
bool dfs(int x,int y)
{
if(x==n&&y==m)
{
return true;
}
else if(mp[x][y-1]=='.')
{
vis(x,y-1);
}
else if(mp[x][y+1]=='.')
{
vis(x,y+1);
}
else if(mp[x-1][y]=='.')
{
vis(x-1,y);
}
else if(mp[x+1][y]=='.')
{
vis(x+1,y);
}
else
{
return false;
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>mp[i][j];
}
}
if(dfs(1,1))
{
printf("Yes");
}
else
{
printf("No");
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<mp[i][j];
}
cout<<endl;
}
return 0;
}
by justalearner @ 2024-04-03 20:26:04
你忘了判出界了(就是说不能走到迷宫外面
是此方欸
by justalearner @ 2024-04-03 20:26:44
@lihans