听取RE声一片

B3625 迷宫寻路

buoluo_1 @ 2024-10-12 21:01:10

#include<bits/stdc++.h>
using namespace std;
int n,m;
char mp[15][15];
bool vis[15][15],flag;

int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
void dfs(int x,int y){
    if (x==n&&y==m){
        flag=true;
        return;
    }
    for(int i=0;i<4;i++){
        int nx=x+dx[i],ny=y+dy[i];
        if (nx>=1&&nx<=n&&ny>=1&&ny<=m&&!vis[nx][ny]&&mp[nx][ny]=='.') {
            vis[nx][ny]=1;
            dfs(nx,ny);
        }
    }
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>mp[i][j];
    vis[1][1]=1;
    dfs(1,1);
    if(flag)printf("Yes");
    else printf("No");
    return 0;
}

by Iochi_YC @ 2024-10-20 13:51:54

#include<bits/stdc++.h>
using namespace std;
int n,m;
char mp[105][105];//太小了 
bool vis[105][105],flag;//太小了

int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};//反了 
void dfs(int x,int y){
    if (x==n&&y==m){
        flag=true;
        return;
    }
    for(int i=0;i<4;i++){
        int nx=x+dx[i],ny=y+dy[i];
        if (nx>=1&&nx<=n&&ny>=1&&ny<=m&&!vis[nx][ny]&&mp[nx][ny]=='.') {
            vis[nx][ny]=1;
            dfs(nx,ny);
        }
    }
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>mp[i][j];
    vis[1][1]=1;
    dfs(1,1);
    if(flag)printf("Yes");
    else printf("No");
    return 0;
}

by Iochi_YC @ 2024-10-20 14:04:07

@FrogCheems 玄关


by yinzixia @ 2024-10-20 15:09:46

@FrogCheems ```cpp int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};


反不反都一样啊

by yinzixia @ 2024-10-20 15:13:32

@FrogCheems 看错了。。


by Iochi_YC @ 2024-10-20 15:13:57

@yinzixia byd


by buoluo_1 @ 2024-10-27 12:14:52

@FrogCheems @yinzixia 过了谢谢


by buoluo_2 @ 2024-11-23 19:50:52

测试


|