• 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. }

     

  • 相关阅读:
    企业部门网络规划设计(课程报告+拓扑图源文件)
    【数据结构】数组和广义表
    pyarmor 加密许可证的使用
    Dobbo微服务项目实战(详细介绍+案例源码) - 2.用户登录
    leetcode-6133:分组的最大数量
    tomcat启动,测试被拒绝连接
    18 【移动Web开发之流式布局】
    【开题报告】基于django+vue新闻发布系统(论文+程序)
    嵌入式linux(imx6ull)下RS485接口配置
    简单使用ThreadLocal、FunctionalInterface、CompletableFuture
  • 原文地址:https://blog.csdn.net/weixin_62802134/article/details/128059359