Dungeon Master(bfs)

本文探讨了在3D迷宫中寻找最短路径的方法,包括输入格式、输出格式及解决算法,帮助玩家理解如何使用BFS算法进行路径搜索。
E - DungeonMaster
TimeLimit:1000MS     MemoryLimit:65536KB     64bitIO Format:%I64d &%I64u

Description

You are trapped in a 3D dungeon and need to findthe quickest way out! The dungeon is composed of unit cubes whichmay or may not be filled with rock. It takes one minute to move oneunit north, south, east, west, up or down. You cannot movediagonally and the maze is surrounded by solid rock on allsides. 

Is an escape possible? If yes, how long will ittake? 

Input

The input consists of a number of dungeons. Eachdungeon 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 thedungeon. 
R and C are the number of rows and columns making up the plan ofeach level. 
Then there will follow L blocks of R lines each containing Ccharacters. Each character describes one cell of the dungeon. Acell full of rock is indicated by a '#' and empty cells arerepresented by a '.'. Your starting position is indicated by 'S'and the exit by the letter 'E'. There's a single blank line aftereach level. Input is terminated by three zeroes for L, R andC.

Output

Each maze generates one line of output. If it ispossible to reach the exit, print a line of theform 
Escaped in x minute(s).

where x is replaced by the shortest time it takes toescape. 
If it is not possible to escape, print theline 
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
#include
#include
#include
using namespace std;

int dir[2]={1,-1};
char arr[30][30][30];
int l,r,c;
struct point
{
    int row,col,level;
    int step;
}p;
int bfs(point s,point e)
{
    int map[r][c][l];
	memset(map,0,sizeof(map));
    queue que;
    point p;
    int x=0,y=0,z=0;
    while(true)
    {
		
		if(s.col==e.col&&s.level==e.level&&s.row==e.row)
		{
			return s.step;
		}
		for(inti=0;i<6;i++)
		{
			if(i<2)
			{
				x=s.col+dir[i];
				y=s.row;
				z=s.level;
			}
			else if(i>=2&&i<4)
			{
				y=s.row+dir[i%2];
				x=s.col;
				z=s.level;
			}
			else if(i>=4&&i<6)
			{
				z=s.level+dir[i%2];
				x=s.col;
				y=s.row;
			}
			if(x<0||x>r-1||y<0||y>c-1||z<0||z>l-1)
				continue;
			if((!map[x][y][z])&&(arr[x][y][z]=='.'||arr[x][y][z]=='E'))
			{
				p.col=x;
				p.level=z;
				p.row=y;
				map[x][y][z]=1;
				p.step=s.step+1;
				que.push(p);
			}
			
		}
		if(que.empty())
			return 0;
		s=que.front();
		que.pop();
    }
	
}

int main()
{
    point s;
    point e;
	while(cin>>l>>r>>c)
	{
		if(l==0&&r==0&&c==0)
		{
			break;
		}
		for(int k=0;k
		{
			for(inti=0;i
			{
				for(int j=0;j
				{
					cin>>arr[i][j][k];
					if(arr[i][j][k]=='S')
					{
						s.col=i;
						s.row=j;
						s.level=k;
						s.step=0;
					}
					if(arr[i][j][k]=='E')
					{
						e.col=i;
						e.row=j;
						e.level=k;
						e.step=0;
					}
				}
			}
		}
		int minute = bfs(s,e);
		if(minute==0)
			cout<<"Trapped!"<<endl;
		else
		{
			cout<<"Escaped in "<<minute<<"minute(s)."<<endl;
		}
	}
    return 0;
}


先展示下效果 https://pan.quark.cn/s/e81b877737c1 Node.js 是一种基于 Chrome V8 引擎的 JavaScript 执行环境,它使开发者能够在服务器端执行 JavaScript 编程,显著促进了全栈开发的应用普及。 在 Node.js 的开发流程中,`node_modules` 文件夹用于存储所有依赖的模块,随着项目的进展,该文件夹可能会变得异常庞大,其中包含了众多可能已不再需要的文件和文件夹,这不仅会消耗大量的硬盘空间,还可能减慢项目的加载时间。 `ModClean 2.0` 正是为了应对这一挑战而设计的工具。 `ModClean` 是一款用于清理 `node_modules` 的软件,其核心功能是移除那些不再被使用的文件和文件夹,从而确保项目的整洁性和运行效率。 `ModClean 2.0` 是此工具的改进版本,在原有功能上增加了更多特性,从而提高了清理工作的效率和精确度。 在 `ModClean 2.0` 中,用户可以设置清理规则,例如排除特定的模块或文件类型,以防止误删重要文件。 该工具通常会保留项目所依赖的核心模块,但会移除测试、文档、示例代码等非运行时必需的部分。 通过这种方式,`ModClean` 能够协助开发者优化项目结构,减少不必要的依赖,加快项目的构建速度。 使用 `ModClean` 的步骤大致如下:1. 需要先安装 `ModClean`,在项目的根目录中执行以下命令: ``` npm install modclean -g ```2. 创建配置文件 `.modcleanrc.json` 或 `.modcleanrc.js`,设定希望清理的规则。 比如,可能需要忽略 `LICENSE` 文件或整个 `docs`...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值