• 2022.11.25Dungeon Master POJ - 2251


    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.

    Is an escape possible? If yes, how long will it take?

    Input

    The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
    L is the number of levels making up the dungeon.
    R and C are the number of rows and columns making up the plan of each level.
    Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.

    Output

    Each maze generates one line of output. If it is possible to reach the exit, print a line of the form

    Escaped in x minute(s).


    where x is replaced by the shortest time it takes to escape.
    If it is not possible to escape, print the line

    Trapped!

    Sample

    InputcopyOutputcopy
    3 4 5
    S....
    .###.
    .##..
    ###.#
    
    #####
    #####
    ##.##
    ##...
    
    #####
    #####
    #.###
    ####E
    
    1 3 3
    S##
    #E#
    ###
    
    0 0 0
    
    Escaped in 11 minute(s).
    Trapped!

    原题链接:传送门 

    题意:走出三维迷宫的最短时间

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. using namespace std;
    10. const int N = 50;
    11. char g[N][N][N];
    12. const int dx[] = {0, 0, 0, 0, -1, 1}, dy[] = {0, 0, -1, 1, 0, 0}, dz[] = {-1, 1, 0, 0, 0, 0};
    13. struct node{int x, y, z;};
    14. int l, r, c;
    15. queue q;
    16. int d[N][N][N];
    17. int bfs(node st) {
    18. while (!q.empty()) q.pop();
    19. q.push(st);
    20. d[st.x][st.y][st.z] = 0;
    21. while (!q.empty()){
    22. node t = q.front();
    23. q.pop();
    24. g[t.x][t.y][t.z] = '#';
    25. for (int i = 0; i < 6; i++) {
    26. int x = t.x + dx[i], y = t.y + dy[i], z = t.z + dz[i];
    27. if (g[x][y][z] == '#') continue;
    28. if (x < 0 || x >= l || y < 0 || y >= r || z < 0 || z >= c) continue;
    29. d[x][y][z] = d[t.x][t.y][t.z] + 1;
    30. if (g[x][y][z] == 'E') return d[x][y][z];
    31. g[x][y][z] = '#';
    32. node stt;
    33. stt.x = x, stt.y = y, stt.z = z;
    34. q.push(stt);
    35. }
    36. }
    37. return 0;
    38. }
    39. int main(){
    40. while (cin >> l >> r >> c && l && r && c){
    41. for (int i = 0; i < l; i++)
    42. for (int j = 0; j < r; j++)
    43. scanf("%s", g[i][j]);
    44. node st;
    45. for (int i = 0; i < l; i++)
    46. for (int j = 0; j < r; j++)
    47. for (int k = 0; k < c; k++)
    48. if (g[i][j][k] == 'S'){
    49. // st = {i, j, k};
    50. st.x = i, st.y = j, st.z = k;
    51. break;
    52. }
    53. int res = bfs(st);
    54. if (res) printf("Escaped in %d minute(s).\n", res);
    55. else puts("Trapped!");
    56. }
    57. return 0;
    58. }

     

  • 相关阅读:
    Ubuntu系统界面启动后启动开机自启动后锁屏
    flutter系列之:构建Widget的上下文环境BuildContext详解
    MySQL基础进阶:汇总数据
    puttygen工具ppk文件版本配置
    【Python】给出n个数,找出这n个数的最大值,最小值,和。
    记一次 .NET某施工建模软件 卡死分析
    vue前端学习——axiosAPI请求
    SQL语句书写规范
    java反射
    拦截器
  • 原文地址:https://blog.csdn.net/weixin_62802134/article/details/128059359