80分求调

B3625 迷宫寻路

机智的娃 @ 2022-07-12 16:58:49

#include<bits/stdc++.h>
using namespace std;
int n,m;
int b[110][110];char a[110][110];
int heng[5]={0,0,-1,0,1};
int shu[5]={0,-1,0,1,0};
void dfs(int x,int y){
    for(int i=1;i<=4;i++){
        if(x+heng[i]<=n&&x+heng[i]>=1&&y+shu[i]<=m&&y+shu[i]>=1){
        if(a[x+heng[i]][y+shu[i]]=='.'&&b[x+heng[i]][y+shu[i]]==0){
            b[x+heng[i]][y+shu[i]]=1;
            dfs(x+heng[i],y+shu[i]);
            return;
        }
        }
    }return ;
}
int main(){

    cin>>n>>m;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            b[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]=='.'){
                dfs(i,j);
            }
        }
    }
    if(b[n][m]==1){
        cout<<"Yes";
    } else cout<<"No";

    return 0;
} 

by Enderich @ 2022-07-12 17:00:27

发了两个?


|