B - Dungeon Master

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!

题意:有一个三维的空间,共l层,每层r行n列,#表示墙壁;有一头龙在S处,每一次他可以上下,前后,左右,六个方向移动。问它到达E点的最短步数。
思路:最典型的bfs求最短路问题了,每次有6个状态,分别将6个状态加入队列就好。切记不可忘了边界判断条件。

#include <iostream>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
 
struct Node{
    int x,y,z;
    int time;
};

char Map[35][35][35];
int book[35][35][35];
int dir[6][3] = {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};
int l,r,c;
int x1,y1,z1;
 
void bfs(){
    queue <Node> Q;
    Node t;
    t.x = x1,t.y = y1,t.z = z1,t.time = 0;
    book[x1][y1][z1] = 1;
    Q.push(t);
    while(!Q.empty()){
        Node res = Q.front();
        Q.pop();
 
        int xx = res.x;
        int yy = res.y;
        int zz = res.z;
        int _time = res.time;
 
        if(Map[xx][yy][zz] == 'E'){     //找到目标
            cout<<"Escaped in "<<_time<<" minute(s)."<<endl;
            return ;
        }
 
        for(int i = 0;i < 6;i ++){      //每一步6个状态
            Node temp;
            int xi = temp.x = xx+dir[i][0];
            int yi = temp.y = yy+dir[i][1];
            int zi = temp.z = zz+dir[i][2];
            temp.time = _time+1;
            if(xi < 1 || xi > l || yi < 1 || yi > r || zi < 1 || zi > c)    continue;       //边界判断
            if(Map[xi][yi][zi] != '#' && !book[xi][yi][zi]){
                book[xi][yi][zi] = 1;
                Q.push(temp);
            }
        }
    }
    cout<<"Trapped!"<<endl;
}

int main()
{
    while(cin>>l>>r>>c){
        if(l == 0 && r == 0 && c == 0)  break;
        for(int i = 1;i <= l;i ++){
            for(int j = 1;j <= r;j ++){
                for(int k = 1;k <= c;k ++){
                    cin>>Map[i][j][k];
                    if(Map[i][j][k] == 'S')
                        x1 = i,y1 = j,z1 = k;
                }
            }
        }
        memset(book,0,sizeof(book));
        bfs();
    }
    return 0;
}

 

系统支持前后端分离架构,涵盖微信、支付宝、百度、头条等主流平台的小程序、APP及公众号,内置多种常见支付方式,具备完善的订单处理机制,界面设计美观,是一款功能完备的商城开源平台。毕业设计是高校教育中的一项关键实践性任务,用于评估学生在专业领域内的知识掌握程度、实践能力和创新思维。该任务通常要求学生结合所学理论,针对某一具体问题提出可行的解决方案或开展一项具有实际价值的研究项目。 在选题阶段,学生需根据个人兴趣、专业方向及现实需求进行选择,并在导师指导下明确研究目标与核心问题,制定研究计划与实施方案。整个过程通常包含资料查阅、需求分析、系统设计、开发实现及测试优化等多个环节,确保研究的完整性与科学性。 在研究过程中,学生需具备较强的自主分析与问题解决能力,可能通过实验、调研、案例研究等方式收集数据并验证假设,从而提升专业技能与实际操作能力。撰写毕业设计报告是核心环节之一,需详细记录研究过程、方法、结果及结论,以全面展示研究成果。同时,这一过程也有助于提升学生的学术表达能力与逻辑思维水平。 最终,毕业设计成果将由导师及相关专家进行评审,评价标准涵盖创新性、应用价值、研究方法的合理性及论文撰写质量等方面。毕业设计的成绩将作为学生学业评估的重要依据,直接影响其毕业资格与学位授予。 总体而言,毕业设计是高校教学体系中的重要组成部分,不仅有助于学生深化专业知识,还能锻炼其独立研究与实践能力,为未来职业发展奠定良好基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值