POJ 2251 Dungeon Master

本文介绍了一种使用三维BFS算法解决迷宫逃脱问题的方法。该算法能够在限定时间内找到从起点到终点的最短路径,适用于由单位立方体构成且被岩石包围的三维迷宫。

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

Dungeon Master
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 17690 Accepted: 6880

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

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <queue>

using namespace std;

int dx[6]= {1,-1,0,0,0,0};
int dy[6]= {0,0,1,-1,0,0};
int dz[6]= {0,0,0,0,1,-1};
int Map[50][50][50];
int vis[50][50][50];

struct node
{
    int x;
    int y;
    int z;
    int step;
} s,e;

queue<node>q;

int BFS()
{
    node t;
    while(!q.empty())
    {
        node a=q.front();
        q.pop();
        for(int i=0; i<6; i++)
        {
            t.x=a.x+dx[i];
            t.y=a.y+dy[i];
            t.z=a.z+dz[i];
            t.step=a.step+1;
            if(Map[t.x][t.y][t.z]&&!vis[t.x][t.y][t.z])
            {
                if(t.x==e.x&&t.y==e.y&&t.z==e.z)
                {
                    return t.step;
                }
                vis[t.x][t.y][t.z]=1;
                q.push(t);
            }
        }
    }
    return 0;
}

int main()
{
    int a,b,c;
    char str;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        if(a==0&&b==0&&c==0)
            break;
       // memset(str,0,sizeof(str));
        memset(Map,0,sizeof(Map));
        memset(vis,0,sizeof(vis));
        while(!q.empty())
        {
            q.pop();
        }
        for(int i=1; i<=a; i++)
        {
            for(int j=1; j<=b; j++)
            {
                for(int k=1; k<=c; k++)
                {
                    //scanf("%c",&str);
                    cin>>str;
                    if(str=='S')
                    {
                        s.x=j;
                        s.y=k;
                        s.z=i;
                        s.step=0;
                        Map[j][k][i]=1;
                        vis[j][k][i]=1;
                        q.push(s);
                    }
                    else if(str=='E')
                    {
                        e.x=j;
                        e.y=k;
                        e.z=i;
                        Map[j][k][i]=1;
                    }
                    else if(str=='.')
                    {
                        Map[j][k][i]=1;
                    }
                }
            }
        }
        int num=BFS();
        if(num)
            printf("Escaped in %d minute(s).\n",num);
        else
            printf("Trapped!\n");
    }
    return 0;
}


内容概要:本文探讨了在MATLAB/SimuLink环境中进行三相STATCOM(静态同步补偿器)无功补偿的技术方法及其仿真过程。首先介绍了STATCOM作为无功功率补偿装置的工作原理,即通过调节交流电压的幅值和相位来实现对无功功率的有效管理。接着详细描述了在MATLAB/SimuLink平台下构建三相STATCOM仿真模型的具体步骤,包括创建新模型、添加电源和负载、搭建主电路、加入控制模块以及完成整个电路的连接。然后阐述了如何通过对STATCOM输出电压和电流的精确调控达到无功补偿的目的,并展示了具体的仿真结果分析方法,如读取仿真数据、提取关键参数、绘制无功功率变化曲线等。最后指出,这种技术可以显著提升电力系统的稳定性与电能质量,展望了STATCOM在未来的发展潜力。 适合人群:电气工程专业学生、从事电力系统相关工作的技术人员、希望深入了解无功补偿技术的研究人员。 使用场景及目标:适用于想要掌握MATLAB/SimuLink软件操作技能的人群,特别是那些专注于电力电子领域的从业者;旨在帮助他们学会建立复杂的电力系统仿真模型,以便更好地理解STATCOM的工作机制,进而优化实际项目中的无功补偿方案。 其他说明:文中提供的实例代码可以帮助读者直观地了解如何从零开始构建一个完整的三相STATCOM仿真环境,并通过图形化的方式展示无功补偿的效果,便于进一步的学习与研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值