大佬求助!!60分!
查看原帖
大佬求助!!60分!
797229
inarticulate_stupid楼主2023/5/31 20:08

#3、#6、#8、#10WA

#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;
}

用的广搜

2023/5/31 20:08
加载中...