inarticulate_stupid @ 2023-05-31 20:08:44
#include<bits/stdc++.h>
using namespace std;
string s[10005];
int t,b[2005][2005],f1,f2,g1,g2,n,m,ax[5]={0,-1,0,1,0},ay[5]={0,0,1,0,-1};
queue<int>x,y,z;
void bfs(int xx,int yy){
x.push(xx);
y.push(yy);
z.push(0);
while(!x.empty())
{
int dx=x.front();
int dy=y.front();
int dz=z.front();
x.pop();
y.pop();
z.pop();
if(dx==n&&dy==m){
cout<<"Yes"<<endl;
return;
}
for(int i=1;i<=4;i++)
{
int bx=dx+ax[i];
int by=dy+ay[i];
if(bx>=1&&bx<=n&&by>=1&&by<=m&&b[bx][by]==0)
{
b[bx][by]=1;
x.push(bx);
y.push(by);
z.push(dz+1);
}
}
}
cout<<"No"<<endl;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>s[i];
for(int j=0;j<s[i].size();j++)
if(s[i][j]=='#')b[i][j]=1;
}
bfs(1,1);
return 0;
}
用的广搜
by zhzkiller @ 2023-05-31 20:34:40
@zhengdaxin 你输入部分下标不对,string是从0到n-1,而你广搜时用的是1到n,改一下,改成
if(s[i][j]=='#') b[i][j+1]=1;
就好了,如果有用给个关注吧
by inarticulate_stupid @ 2023-06-01 11:45:19
@zhzkiller 蟹蟹!