Dungeon Master POJ - 2251 (搜索)

来源:https://www.cnblogs.com/smallhester/archive/2018/08/29/9557190.html
-Advertisement-
Play Games

Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48605 Accepted: 18339 Description You are trapped in a 3D dungeon and need t ...


Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 48605   Accepted: 18339

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

Ulm Local 1997  

題意:給你一個多維的迷宮,問能不能可以從起點走到終點,可以上下穿梭層數,也可以東南西北走,都是一秒一個單位,可以到終點就輸出步數,不可以就輸出那句話

思路:其實和普通的二維迷宮差不多,就是多了一個層數,也就是多了兩個方向(上下層數)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
#define ll long long
int const maxn = 35;
const int mod = 1e9 + 7;
int gcd(int a, int b) {
    if (b == 0) return a;  return gcd(b, a % b);
}

char map[maxn][maxn][maxn];
int vis[maxn][maxn][maxn];
int k,n,m,sx,sy,sz,ex,ey,ez;
int dir[6][3]={{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};

struct node
{
    int x,y,z,step;
};
int check (int x,int y,int z)
{
    if(x<0 || y<0 || z<0 || x>=k || y>=n || z>=m)
        return 1;
    else if(map[x][y][z]=='#')
        return 1;
    else if(vis[x][y][z])
        return 1;
    return 0;
}

int bfs()
{
    node a,next;
    queue<node>que;
    a.x=sx;  a.y=sy;  a.z=sz;
    a.step=0;
    vis[sx][sy][sz]=1;
    que.push(a);
    while(!que.empty())
    {
        a=que.front();
        que.pop();
        if(a.x == ex && a.y == ey && a.z == ez)
            return a.step;
        for(int i=0;i<6;i++)
        {
            next=a;
            next.x=a.x+dir[i][0];
            next.y=a.y+dir[i][1];
            next.z=a.z+dir[i][2];
            if(check(next.x,next.y,next.z))
                continue;
            vis[next.x][next.y][next.z]=1;
            next.step=a.step+1;
            que.push(next);

        }
    }
    return 0;

}


int main()
{
    while(~scanf("%d %d %d",&k,&n,&m))
    {
        if(k==0 && n==0 && m==0)
            break;
        for(int i=0;i<k;i++)
        {
            for(int j=0;j<n;j++)
            {
                scanf("%s",map[i][j]);
                for(int r=0;r<m;r++)
                {
                    if(map[i][j][r]=='S')
                    {
                        sx=i;sy=j;sz=r;
                    }
                    else if(map[i][j][r]=='E')
                    {
                        ex=i;ey=j;ez=r;
                    }
                }
            }
        }
        memset(vis,0,sizeof(vis));
        int ans;
        ans=bfs();
        if(ans)
            printf("Escaped in %d minute(s).\n",ans);
        else
            printf("Trapped!\n");
    }
    return 0;
}

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Spring提供了一個AOP框架,讓我把切麵插入到方法執行的周圍。 1、概念 定義通用功能,通過申明定義這些功能要以何種方式在何處應用,而不需要修改受影響的類。這些通用功能可以模塊化為特殊的類,即切麵。 連接點:連接點是一個應用執行過程中能夠插入一個切麵的點(Spring只支持方法級別的連接點) 切 ...
  • 假設Andy和Doris想在晚餐時選擇一家餐廳,並且他們都有一個表示最喜愛餐廳的列表,每個餐廳的名字用字元串表示。 你需要幫助他們用最少的索引和找出他們共同喜愛的餐廳。 如果答案不止一個,則輸出所有答案並且不考慮順序。 你可以假設總是存在一個答案。 示例 1: 輸入: ["Shogun", "Tap ...
  • 需求:實體是blog 和author 關係是一對一,查詢 blog 以及 blog 的作者信息 嵌套查詢 xml select from blog where bid = {id, jdbcType=INTEGER} ...
  • 引言 還記得大三時上培訓班的是時候,當時的培訓老師說自己是本地講解spring最好的講師,但是後來等我實習了看了《Spring 3.x 企業應用開發實戰》以及後續版本《精通Spring+4.x++企業應用開發實戰》才發現,這位培訓老師就是基本按照《Spring 3.x 企業應用開發實戰》給我們講sp ...
  • #以下是我自己在聯繫列表中所編寫的語句:names=["zangsan",'lisi','wangermazi','Xiaoliuzi','dabiaoge','牛erbiaodi']# 0 1 2 3 4 5 print(names[2])#簡單取值#取lisi和wangermaziprint(n ...
  • 11種狀態解析 LISTEN 等待從任何遠端TCP 和埠的連接請求。 SYN_SENT 發送完一個連接請求後等待一個匹配的連接請求。 SYN_RECEIVED 發送連接請求並且接收到匹配的連接請求以後等待連接請求確認。 ESTABLISHED 表示一個打開的連接,接收到的數據可以被投遞給用戶。連接 ...
  • 剛剛開始學習c++。之前c的內容掌握的也不多,基本只是一本概論課的程度,以前使用c的struct寫過的鏈表、用python寫過簡單的數據結構,就試著把兩者用c++寫出來,也是對c++的class,以及繼承中的public/protected/private的性質進行初步瞭解。第一次寫頭文件.h和源文 ...
  • ASCII(American Standard Code for Information Interchange,美國信息互換標準代碼)是一套基於拉丁字母的字元編碼,共收錄了 128 個字元,用一個位元組就可以存儲,它等同於國際標準 ISO/IEC 646。ASCII 規範於 1967 年第一次發佈, ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...