@rensiwei 求调

B3625 迷宫寻路

qqbrobin @ 2024-08-21 15:20:14

#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[105][105];
int f[105][105];
int fy[4]={-1,1,0,0};
int fx[4]={0,0,1,-1};
int dfs(int x,int y){
    for(int i=0;i<4;i++){
        int dx=x+fx[i];
        int dy=y+fy[i];
        if(dx>=1&&dx<=n&&dy>=1&&dy<=m&&!f[dx][dy]&&a[dx][dy]=='.'){
            if(dx==n&&dy==m){
                cout<<"Yes";
                return 0;
            }
            f[dx][dy]=1;
            a[dx][dy]='#';
            dfs(dx,dy);
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    if(!dfs(1,1)){
        cout<<"No";
    }

    return 0;                       
}

by rensiwei @ 2024-08-21 15:41:01

@qqbrobin

AC了,由于我不能把代码发在这里,我放在聊天里的云剪贴板里了


|