对拍,感谢@Queue_Hao 这位大佬

B3625 迷宫寻路

QWQ_Xiari @ 2023-07-03 15:39:56

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
long long k[3],t,n,m,maxx,x2,y2,x3,y3,aa[10000][10000],aa1[10000][10000],can=0,qw;
char a[10000][10000];
void bfs(int xx,int yy) {//测量图的可用性
    //cout<<xx<<" "<<yy<<endl;

    if(yy==y2&&xx==x2) {
        qw=1;
    } else {
        if(can==0) {
            if(aa[xx+1][yy]==1) {
                aa[xx+1][yy]=0;
                bfs(xx+1,yy);
                aa[xx+1][yy]=1;
            }
        }
        if(can==0) {
            if(aa[xx][yy+1]==1) {
                aa[xx][yy+1]=0;
                bfs(xx,yy+1);
                aa[xx][yy+1]=1;
            }
        }
        if(can==0) {
            if(aa[xx-1][yy]==1) {
                aa[xx-1][yy]=0;
                bfs(xx-1,yy);
                aa[xx-1][yy]=1;
            }
        }
        if(can==0) {
            if(aa[xx][yy-1]==1) {
                aa[xx][yy-1]=0;
                bfs(xx,yy-1);
                aa[xx][yy=-1]=1;
            }
        }
    }
}
void kl() { //建图

}

int main() {
    unsigned seed;
    seed = time(0);
    srand(seed);
    cin>>n>>m;
    system("cls");
    while(qw!=1) {
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=m; j++) {
                int yyy=rand()%2+1;
                if(yyy==1) {
                    aa1[i][j]=aa[i][j]=1;

                } else {
                    aa1[i][j]=aa[i][j]=0;
                }
            }
        }
        aa1[x3][y3]=aa1[x2][y2]=1;
        x3=1;
        x2=n;
        y3=1;
        y2=m;
        bfs(x3,y3);
    }
    int yuu=rand()%5+1;

    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            if(aa1[i][j]==0) {
                cout<<'#';
            }
            if(aa1[i][j]==1) {
                cout<<'.';
            }

        }
        cout<<endl;
    }
    return 0;
}

by QWQ_Xiari @ 2023-07-03 15:41:19

本人比较粗心如有Bug请@本人谢谢


by BlackPanda @ 2023-07-03 15:51:19

@Steve_xh gen,不是std


by Steve_xh @ 2023-07-03 15:52:28

@Queue_Hao 看错了,眼瞎(


by BlackPanda @ 2023-07-03 16:26:38

@xiari 好像复杂度有点高(


by QWQ_Xiari @ 2023-07-03 16:31:07

@Queue_Hao 深搜改的确实有点


by BlackPanda @ 2023-07-03 16:51:36

@xiari 有个时间复杂度比较低的思路,先随机走一条路线然后剩下的随机覆盖成 #


by QWQ_Xiari @ 2023-07-03 18:16:13

@Queue_Hao 不错的思路,待会去试试


|