POJ 2251 - Dungeon Master

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 23092 Accepted: 8985

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 即可。
 1 #include <iostream>
 2 #include <cstring>
 3 #include <queue>
 4 using namespace std;
 5 struct pr{
 6     int x,y,z,t;
 7  };
 8  const int x[10]={0,0,0,1,-1,0,0},y[10]={0,1,-1,0,0,0,0},z[10]={0,0,0,0,0,1,-1};
 9  int a,b,c,sx,sy,sz;
10  char map[111][111][111];
11  int flag[111][111][111];
12  queue<pr> s;
13  pr q,temp;
14  void bfs()
15  {
16     int i,j,k;
17     while(!s.empty())
18     s.pop();
19     memset(flag,0,sizeof(flag));
20     flag[sx][sy][sz]=1;
21     q.x=sx;q.y=sy; q.z=sz; q.t=0;
22     s.push(q);
23     while(!s.empty())
24     {
25         q=s.front();
26         s.pop(); 
27         for(i=1;i<=6;i++)
28             if(q.x+x[i]>0&&
29                 q.x+x[i]<=a&&
30                 q.y+y[i]>0&&
31                 q.y+y[i]<=b&&
32                 q.z+z[i]<=c&&
33                 q.z+z[i]>0)
34                 {
35                 if(map[q.x+x[i]][q.y+y[i]][q.z+z[i]]!='#')
36                     if(!flag[q.x+x[i]][q.y+y[i]][q.z+z[i]])
37                     {
38                         flag[q.x+x[i]][q.y+y[i]][q.z+z[i]]=1;
39                         temp.x=q.x+x[i];
40                         temp.y=q.y+y[i];
41                         temp.z=q.z+z[i];
42                         temp.t=q.t+1;
43                         if(map[q.x+x[i]][q.y+y[i]][q.z+z[i]]=='E')
44                         {
45                             cout<<"Escaped in "<<temp.t<<" minute(s)."<<endl;
46                             return;
47                         }
48                         s.push(temp);
49                     }
50                 }
51     }
52     cout<<"Trapped!"<<endl;
53  }
54 int main()
55 {
56     int i,j,k;
57     while(cin>>a>>b>>c,a+b+c)
58     {
59         for(i=1;i<=a;i++)
60             for(j=1;j<=b;j++)
61                 for(k=1;k<=c;k++)
62             {
63                 cin>>map[i][j][k];
64                 if(map[i][j][k]=='S')
65                 {
66                     sx=i;
67                     sy=j;
68                     sz=k;
69                 }
70             }
71         bfs();
72     }
73 }
 
 

转载于:https://www.cnblogs.com/nicetomeetu/p/5155796.html

基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip基于MATLAB实现旅行推销员问题(TSP)的代码+项目说明(课程大作业)+测试数据.zip 【备注】 1、该资源内项目代码百分百可运行,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值