POJ 2251 Dungeon Master bfs

本文深入探讨了深度学习技术在音视频处理领域的应用,包括AI音视频处理、图像处理AR特效、音视频直播流媒体等方向,详细介绍了各种应用场景及实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Dungeon Master
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 24602 Accepted: 9525

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!

Source


3d bfs//原来不知道哪里错了盯着代码debug半天没结果 重新手敲一遍就a了- -

ACcode:

#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#define maxn 33
using namespace std;
char mapp[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn];
int to[][3]={1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1};
int n,m,l;
struct N{
    int x,y,z,t;
};
N my,no,ne;
bool ju(N a){
    if(a.x<0||a.x>=n||a.y<0||a.y>=m||a.z<0||a.z>=l||mapp[a.x][a.y][a.z]=='#'||vis[a.x][a.y][a.z])return 0;
    return 1;
}
void bfs(){
    memset(vis,false,sizeof(vis));
    queue<N>q;
    q.push(my);
    vis[my.x][my.y][my.z]=1;
    while(!q.empty()){
        no=q.front();q.pop();
        for(int i=0;i<6;++i){
            ne=no;
            ne.x+=to[i][0];
            ne.y+=to[i][1];
            ne.z+=to[i][2];
            ne.t++;
            if(ju(ne)){
                if(mapp[ne.x][ne.y][ne.z]=='E'){
                     printf("Escaped in %d minute(s).\n",ne.t);
                     return;
                }
                q.push(ne);
                vis[ne.x][ne.y][ne.z]=1;
            }
        }
    }
    printf("Trapped!\n");
}
int main(){
    while(~scanf("%d%d%d",&n,&m,&l)&&(n+m+l)){
        for(int i=0;i<n;++i)
            for(int j=0;j<m;++j)
                for(int z=0;z<l;++z){
                    cin>>mapp[i][j][z];
                    if(mapp[i][j][z]=='S'){
                        my.x=i;
                        my.y=j;
                        my.z=z;
                        my.t=0;
                    }
            }
        bfs();
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值