C98 #1#2#4#9 AC,其余T

B3625 迷宫寻路

IAKIOI321 @ 2024-05-17 23:26:12

rt

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<cstdio>
#include<ctime>
#include<cmath>
#include<map>
using namespace std;
int a[101][101];
char c;
int n,m;
int next[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int minn=99999;
int flag;

int book[101][101];
void dfs(int x,int y){
    int nextx=1,nexty=1;
    if(x==n&&y==m){
        cout<<"Yes"<<endl;
        flag=1;
    }
    if(flag==1) return;
    for(int k=0;k<=3;k++){
        nextx=x+next[k][0];
        nexty=y+next[k][1];
        if(nextx<1||nextx>n||nexty<1||nexty>m) continue; 
        if(a[nextx][nexty]==0&&book[nextx][nexty]==0){
            book[nextx][nexty]=1;
            dfs(nextx,nexty);
            book[nextx][nexty]=0;
        }
    }
    return;
}
int main(){
    book[1][1]=1;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>c;
            if(c=='#') a[i][j]=1;
        }
    }
    dfs(1,1);
    if(flag==0) cout<<"No"<<endl;
    return 0;
}

记录


by xuhaoyu_ @ 2024-05-18 00:52:33

book[nextx][nexty]=1;

dfs(nextx,nexty);

book[nextx][nexty]=0;//这行不要


by IAKIOI321 @ 2024-05-18 07:49:18

@xuhaoyu_ 然后T变WA了...


by IAKIOI321 @ 2024-05-18 07:50:17

@xuhaoyu_ 当我没说,感谢dalao


by JeremyXie @ 2024-05-18 08:25:35

哪里来的Mrock?


|