zoukankan      html  css  js  c++  java
  • POJ 3279 Dungeon Master

    Dungeon Master
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 21242   Accepted: 8265

    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!
    三维BFS 注意xyz别弄混了
    /* ***********************************************
    Author        :pk29
    Created Time  :2015/8/19 18:40:40
    File Name     :4.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10000+10
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    struct node{
        int x,y,z;
        int dist;
    };
    bool cmp(int a,int b){
        return a>b;
    }
    int l,r,c;
    char mp[50][50][50];
    int vis[50][50][50];
    int sx,sy,sz,ex,ey,ez;
    int dir[6][3]={0,1,0,0,0,1,0,0,-1,1,0,0,-1,0,0,0,-1,0};
    
    void bfs(){
        node u,v;
        u.x=sx,u.y=sy,u.z=sz, u.dist=0;
        queue<node>q;
        q.push(u);
        int mark=0;
        vis[u.x][u.y][u.z]=1;
        while(!q.empty()){
            u=q.front(),q.pop();
            if(u.x==ex&&u.y==ey&&u.z==ez){
                mark=1;printf("Escaped in %d minute(s).
    ",u.dist);break;
            }
            for(int i=0;i<6;i++){
                int nx=u.x+dir[i][0];
                int ny=u.y+dir[i][1];
                int nz=u.z+dir[i][2];
                if(!vis[nx][ny][nz]&&mp[nx][ny][nz]!='#'&&nx>=1&&ny>=1&&nz>=1&&nx<=r&&ny<=c&&nz<=l){
                    v.x=nx,v.y=ny,v.z=nz;
                    v.dist=u.dist+1;
                    q.push(v);
                    vis[nx][ny][nz]=1;
                }
            }
        }
        if(!mark)printf("Trapped!
    ");
    }
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        while(cin>>l>>r>>c){
            if(l==0&&c==0&&r==0)break;
            for(int i=1;i<=l;i++)
                for(int j=1;j<=r;j++)
                    for(int k=1;k<=c;k++){
                        cin>>mp[j][k][i];
                        if(mp[j][k][i]=='S')sx=j,sy=k,sz=i;
                        if(mp[j][k][i]=='E')ex=j,ey=k,ez=i;
                    }
            cle(vis);
            //cout<<sx<<sy<<sz<<endl;
            //cout<<ex<<ey<<ez<<endl;
    
            bfs();
        }
        return 0;
    }
  • 相关阅读:
    Linux基本知识
    Linux 基金会发起开源创新计划,为全球对抗 COVID-19 提供基础架构
    单片机程序设计有十层功力,你现在在哪一层?
    C语言太复杂?CUDA Python也能实现并行计算加速!
    Java 基础 子类赋值给父类问题
    SpringBlade AVUE 拖拽排序
    java 基础 Long类型 判断是否相等
    数字量输入模块和模拟量输入模块的区别是什么?
    模拟量输入模块和模拟量输出模块的应用范围
    NB-IOT关键技术分析
  • 原文地址:https://www.cnblogs.com/pk28/p/4743157.html
Copyright © 2011-2022 走看看