zoukankan      html  css  js  c++  java
  • poj 2251 -- Dungeon Master

    Dungeon Master
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 16468   Accepted: 6395

    Description

    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 Input

    3 4 5
    S....
    .###.
    .##..
    ###.#
    
    #####
    #####
    ##.##
    ##...
    
    #####
    #####
    #.###
    ####E
    
    1 3 3
    S##
    #E#
    ###
    
    0 0 0
    

    Sample Output

    Escaped in 11 minute(s).
    Trapped!

     1 /*======================================================================
     2  *           Author :   kevin
     3  *         Filename :   DungeonMaster.cpp
     4  *       Creat time :   2014-08-02 09:40
     5  *      Description :
     6 ========================================================================*/
     7 #include <iostream>
     8 #include <cstdio>
     9 #include <cstring>
    10 #include <queue>
    11 using namespace std;
    12 struct Node
    13 {
    14     int x,y,z;
    15     char c;
    16 };
    17 int cnt[31][31][31],vis[31][31][31],xx,yy,zz;
    18 int cc[6][3]={{-1,0,0},{1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
    19 char s[31][31][31];
    20 void BFS(int a,int b,int c)
    21 {
    22     queue<Node>que;
    23     Node node,ch,sh;
    24     int q,w,e;
    25     node.c=s[a][b][c];
    26     node.x=a;node.y=b;node.z=c;
    27     que.push(node);
    28     while(!que.empty()){
    29         ch=que.front();
    30         if(ch.c=='E')
    31           break;
    32         que.pop();
    33         for(int i=0;i<6;i++){
    34             q=ch.x+cc[i][0];
    35             w=ch.y+cc[i][1];
    36             e=ch.z+cc[i][2];
    37             if(!vis[q][w][e] && q>=0&&q<xx && w>=0&&w<yy &&
    38                         e>=0&&e<zz){
    39                 cnt[q][w][e]=cnt[ch.x][ch.y][ch.z]+1;
    40                 sh.c=s[q][w][e];
    41                 sh.x=q;sh.y=w;sh.z=e;
    42                 que.push(sh);
    43                 vis[q][w][e]=1;
    44             }
    45         }
    46     }
    47 }
    48 int main()
    49 {
    50     int as,bs,cs,ae,be,ce;
    51     while(scanf("%d%d%d",&xx,&yy,&zz)!=EOF && xx+yy+zz){
    52         memset(s,0,sizeof(s));
    53         memset(vis,0,sizeof(vis));
    54         memset(cnt,0,sizeof(cnt));
    55         for(int i=0;i<xx;i++){
    56             for(int j=0;j<yy;j++){
    57                 getchar();
    58                 for(int k=0;k<zz;k++){
    59                     scanf("%c",&s[i][j][k]);
    60                     if(s[i][j][k]=='S'){
    61                         as=i;bs=j;cs=k;
    62                     }
    63                     if(s[i][j][k]=='E'){
    64                         ae=i;be=j;ce=k;
    65                     }
    66                     if(s[i][j][k]=='#'){
    67                         vis[i][j][k]=1;
    68                     }
    69                 }
    70             }
    71             getchar();
    72         }
    73         vis[as][bs][cs]=1;
    74         BFS(as,bs,cs);
    75         if(cnt[ae][be][ce]==0){
    76             printf("Trapped!
    ");
    77         }
    78         else printf("Escaped in %d minute(s).
    ",cnt[ae][be][ce]);
    79     }
    80     return 0;
    81 }
    View Code
  • 相关阅读:
    SPOJ 1812 LCS2 后缀自动机
    [APIO2014]回文串 后缀自动机_Manancher_倍增
    SPOJ8222 NSUBSTR
    [HAOI2016]找相同字符 广义后缀自动机_统计出现次数
    洛谷 P3804 【模板】后缀自动机 统计单词出现次数
    洛谷 P1368 工艺 后缀自动机 求最小表示
    力扣题目汇总(反转字符串中的单词,EXCEL表列序号,旋置矩阵)
    力扣题目汇总(重复N次元素,反转字符串,斐波那契数)
    力扣题目汇总(机器人返回原点,按奇偶排序,数字的补数)
    博客园美化的第二天(动态设置,以及结合ps制作)
  • 原文地址:https://www.cnblogs.com/ubuntu-kevin/p/3886542.html
Copyright © 2011-2022 走看看