ldu 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!
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#define mem(a,b) memset(a,b,sizeof(a))
using  namespace std;
int max(int a,int b){ return a>b?a:b;}
int maxn (int a,int b,int c){return max(max(a,b),max(b,c));}
int vis[40][40][40];
int dis[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
char a[35][35][35];
int x1,y1,z1;
int n,t,m;
int i,j,k;
typedef struct node {
     int x,y,z,time;
}p;
void bfs()
{
    mem(vis,0);
    p n1,temp;
    queue<node>P;
    n1.x=x1;n1.y=y1;n1.z=z1;n1.time=0;
    vis[n1.x][n1.y][n1.z]=1;
    P.push(n1);
    while(!P.empty())
    {
        n1=P.front();
        P.pop();
        if(a[n1.x][n1.y][n1.z]=='E')
        {
            printf("Escaped in %d minute(s).\n",n1.time);
            return ;
        }
        for(i=0;i<6;i++)
        {
            temp=n1;
            temp.x+=dis[i][0];
            temp.y+=dis[i][1];
            temp.z+=dis[i][2];
            temp.time++;
            if(!vis[temp.x][temp.y][temp.z]&&temp.x>=0&&temp.x<n&&temp.y>=0&&temp.y<m&&temp.z>=0&&temp.z<t&&a[temp.x][temp.y][temp.z]!='#')
            {
                vis[temp.x][temp.y][temp.z]=1;
                P.push(temp);
            }
        }
    }
    printf("Trapped!\n");
}
int main()
{


	while(~scanf("%d%d%d",&n,&m,&t))
    {
        if(!m&&!n&&!t) break;
        mem(a,'\0');
         for(i=0;i<n;i++)
         {
             for(j=0;j<m;j++)
             {
                 scanf("%s",a[i][j]);
                 {
                     for(k=0;k<t;k++)
                     {
                         if(a[i][j][k]=='S')
                         {
                             x1=i;y1=j;z1=k;
                             break;
                         }
                     }
                 }
                 getchar();
             }
             getchar();
         }
         bfs();
    }
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LDU分解是一种对数学矩阵进行分解的方法,它把一个矩阵分解为一个下三角矩阵L,一个对角矩阵D和一个上三角矩阵U的乘积。在计算机科学领域,CSDN是一个知名的技术社区,提供了大量的技术文章和教程。如果要用中文回答LDU分解CSDN,可以从以下几个方面来进行回答。 首先,可以简要介绍LDU分解的原理和应用。LDU分解是一种用来简化矩阵计算的方法,可以帮助我们更容易地理解和求解复杂的线性方程组。在实际应用中,LDU分解可以用于解决物理、工程、经济等领域的实际问题。 其次,可以探讨CSDN在技术领域的作用和影响。CSDN作为国内领先的IT技术社区,汇集了大量的技术人员和专家,为广大技术爱好者提供了学习、交流和分享的平台。在CSDN上,我们可以获取最新的技术动态、学习最新的编程语言和框架,并且还可以通过博客、问答等方式了解其他技术人员的经验和见解。 最后,可以谈谈如何利用CSDN平台获取关于LDU分解的相关知识。通过CSDN平台,我们可以搜索到大量关于LDU分解的文章、教程和讨论,可以通过阅读他人的经验和观点来更好地理解和应用LDU分解。同时,我们也可以在CSDN上发布自己的学习笔记和疑惑,与其他技术人员进行交流和讨论,共同进步。 总的来说,LDU分解和CSDN都在各自领域发挥着重要的作用,通过CSDN可以获取关于LDU分解的相关知识,从而更好地学习和应用这种数学方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值