签到

05月06日
尚未签到

共有回帖数 0

    岁月流逝

    等级:
    如题
    利用二维N*N数组存储
    只能有一个通路
    从(0,0)-(n-1,n-1)(也可为其他任意边缘点)
    其余还有若干迷惑通道
    #include stdio.h
    #include stdlib.h
    #include time.h

    const int MAX_WIDTH = 39, MAX_HEIGHT = 11;
    bool a[MAX_WIDTH*2+3][MAX_HEIGHT*2+3] = {};

    void DFS(int x, int y)
    {
    ____static int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1};
    ____a[x*2][y*2] = true;
    ____for (int d = rand()%4, dd = rand()%2 ? 1 : 3, i = 0; i  4; ++i, d = (d+dd)%4)
    ________if (!a[x*2+dx[d]*2][y*2+dy[d]*2])
    ________{
    ____________a[x*2+dx[d]][y*2+dy[d]] = true;
    ____________DFS(x+dx[d], y+dy[d]);
    ________}
    }

    int main()
    {
    ____for (int i = 0; i  MAX_WIDTH*2+3; ++i)
    ________a[0] = true, a[MAX_HEIGHT*2+2] = true;
    ____for (int i = 0; i  MAX_HEIGHT*2+3; ++i)
    ________a[0] = true, a[MAX_WIDTH*2+2] = true;
    ____srand(time(NULL));
    ____a[1][2] = true;
    ____a[MAX_WIDTH*2+1][MAX_HEIGHT*2] = true;
    ____DFS(rand()%MAX_WIDTH+1, rand()%MAX_HEIGHT+1);
    ____for (int j = 1; j  MAX_HEIGHT*2+2; ++j, putchar('n'))
    ________for (int i = 1; i  MAX_WIDTH*2+2; ++i)
    ____________putchar(a[j] ? ' ' : '|');
    ____return 0;
    }

    楼主 2015-12-24 21:08 回复

共有回帖数 0
  • 回 帖
  • 表情 图片 视频
  • 发表

登录直线网账号

Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号 意见反馈 | 关于直线 | 版权声明 | 会员须知