60 想不懂一点

B3625 迷宫寻路

_XSOI_ @ 2023-10-21 21:04:39

#include<iostream>
#include<cmath>
using namespace std;
char map[1100][1100];
bool vis[1100][1100];
int dx[5] = {0,0,0,1,-1},dy[5] = {0,1,-1,0,0};
int ans,n,m;
int dfs(int x,int y){
    if(x == n and y == m){
        return 1;
    }
    if(map[1][1] == '#'){
        return 0;
    }
    for(int i = 1;i <= 4;i ++){
        int n_dx = x + dx[i];
        int n_dy = y + dy[i];
        if(n_dx > 1 and n_dx <= n and n_dy > 1 and n_dy <= m){
            if(map[n_dx][n_dy] == '.' and vis[n_dx][n_dy] == 0){
                vis[n_dx][n_dy] = 1;
                dfs(n_dx,n_dy);
            }
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i = 1;i <= n;i ++){
        for(int j = 1;j <= m;j ++){
            cin>>map[i][j];
        }
    }
    dfs(1,1);
    if(vis[n][m] == 0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

在线等,急!


by _XSOI_ @ 2023-10-21 21:14:48

已解决,没加等号


|