四十分求调

B3625 迷宫寻路

xu_chen_jun @ 2024-12-30 19:42:39

四十分求调 好心点吧

#include<bits/stdc++.h>
using namespace std;
int n,m,dx[]={0,0,1,-1},dy[]={1,-1,0,0},q[2][10010],ma[105][105];
char k;
int f,r,x,y;
int flag=0;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>k;
            if(k=='#'){
                ma[i][j]=0;
            }else{
                ma[i][j]=1;
            }
        }
    }
    x=y=1;
    f=r=1;
    q[0][r]=x;
    q[1][r]=y;
    while(r<=f){
        int xx=q[0][f],yy=q[1][f];
        for(int i=0;i<4;i++){
            x=xx+dx[i];
            y=yy+dy[i];
            if(ma[x][y]==1){
                r++;
                q[0][r]=x;
                q[1][r]=y;
                ma[x][y]=0;
            }
            if(x==n&&y==m){
                cout<<"Yes";
                flag=1;
                break;
            }
        }
        f++;
    }
    if(flag==0){
        cout<<"No";
    }
    return 0;
} 

//帮帮吧!!!

by chen_wei_zhi @ 2024-12-30 22:53:07

题?


by xu_chen_jun @ 2025-01-02 17:52:18

@chen_wei_zhi

什么题?


by xu_chen_jun @ 2025-01-02 17:55:56

题是(题目传送门)


|