POJ 2251 Dungeon Master(宽搜)

本文详细解析了POJ2251 Dungeon Master问题的解决思路,利用三维地图进行迷宫逃脱,通过BFS算法寻找从起点到终点的最短路径,实现快速逃出迷宫。

POJ 2251 Dungeon Master

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!

题意:给你一个三维地图,‘S’为起点,‘E’为终点,‘.’表示能走,‘#’表示不能走,如果能从起点走到终点,就输出最少走多少步,如果无法到达终点,输出‘Trapped!’。
题解:正常bfs就行

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int maxn=50;
int l,r,c;
char map[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn];
bool flag;//记录能否到达终点 
struct edge{
	int x,y,z;
	int s;
};
queue<edge> q;
int main()
{
	while(1)
	{
		scanf("%d%d%d",&l,&r,&c);
		if(l==0&&r==0&&c==0)
		{
			break;
		}
		edge start;
		memset(map,'\0',sizeof(map));
		for(int i=1;i<=l;i++)
		{
			for(int j=1;j<=r;j++)
			{
				for(int k=1;k<=c;k++)
				{
					cin>>map[i][j][k];
					if(map[i][j][k]=='S')
					{
						flag=1;
					 	start.x=i,start.y=j,start.z=k;
					 	start.s=0;
					}
				}
			}
		}
		while(!q.empty())
		{
			q.pop();
		}
		memset(vis,0,sizeof(vis));
		q.push(start);
		vis[start.x][start.y][start.z]=1;
		while(!q.empty())
		{
			edge v=q.front();
			q.pop();
			if(map[v.x][v.y][v.z]=='E')
			{
				flag=0;
				printf("Escaped in %d minute(s).\n",v.s);
				break;
			}
			v.s++;
			edge u;
			if(v.x-1>=1)
			{
				u=v;
				u.x=v.x-1;
				if(!vis[u.x][u.y][u.z]&&map[v.x][v.y][v.z]!='#')
				{
					q.push(u);
					vis[u.x][u.y][u.z]=1;
				}
			}
			if(v.x+1<=l)
			{
				u=v;
				u.x=v.x+1;
				if(!vis[u.x][u.y][u.z]&&map[v.x][v.y][v.z]!='#')
				{
					q.push(u);
					vis[u.x][u.y][u.z]=1;
				}
			}
			if(v.y-1>=1)
			{
				u=v;
				u.y=v.y-1;
				if(!vis[u.x][u.y][u.z]&&map[v.x][v.y][v.z]!='#')
				{
					q.push(u);
					vis[u.x][u.y][u.z]=1;
				}
			}
			if(v.y+1<=r)
			{
				u=v;
				u.y=v.y+1;
				if(!vis[u.x][u.y][u.z]&&map[v.x][v.y][v.z]!='#')
				{
					q.push(u);
					vis[u.x][u.y][u.z]=1;	
				}
			}
			if(v.z-1>=1)
			{
				u=v;
				u.z=v.z-1;
				if(!vis[u.x][u.y][u.z]&&map[v.x][v.y][v.z]!='#')
				{
					q.push(u);
					vis[u.x][u.y][u.z]=1;	
				}
			}
			if(v.z+1<=c)
			{
				u=v;
				u.z=v.z+1;
				if(!vis[u.x][u.y][u.z]&&map[v.x][v.y][v.z]!='#')
				{
					q.push(u);
					vis[u.x][u.y][u.z]=1;	
				}
			}
		}
		if(flag)
		{
			printf("Trapped!\n");
		}
	}
	return 0;
}
考虑可再生能源出力不确定性的商业园区用户需求响应策略(Matlab代码实现)内容概要:本文围绕“考虑可再生能源出力不确定性的商业园区用户需求响应策略”展开,结合Matlab代码实现,研究在可再生能源(如风电、光伏)出力具有不确定性的背景下,商业园区如何制定有效的需求响应策略以优化能源调度和提升系统经济性。文中可能涉及不确定性建模(如场景生成与缩减)、优化模型构建(如随机规划、鲁棒优化)以及需求响应机制设计(如价格型、激励型),并通过Matlab仿真验证所提策略的有效性。此外,文档还列举了大量相关的电力系统、综合能源系统优化调度案例与代码资源,涵盖微电网调度、储能配置、负荷预测等多个方向,形成一个完整的科研支持体系。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及从事能源系统规划与运行的工程技术人员。; 使用场景及目标:①学习如何建模可再生能源的不确定性并应用于需求响应优化;②掌握使用Matlab进行商业园区能源系统仿真与优化调度的方法;③复现论文结果或开展相关课题研究,提升科研效率与创新能力。; 阅读建议:建议结合文中提供的Matlab代码实例,逐步理解模型构建与求解过程,重点关注不确定性处理方法与需求响应机制的设计逻辑,同时可参考文档中列出的其他资源进行扩展学习与交叉验证。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值