3D dungeon

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述
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? 

 
输入
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.
输出
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!

样例输入
3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0
样例输出
Escaped in 11 minute(s).
Trapped! 还是感觉广搜比深搜简单点
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#define MAX 35
using namespace std;
int n,m,k;
int x1,x2,y1,y2,z1,z2;
char map[MAX][MAX][MAX];
int vis[MAX][MAX][MAX];
struct node
{
int x,y,z,step;
friend bool operator < (node a,node b)
{
return a.step>b.step;
}
};
void bfs()
{
int i,j;
int move[6][3]={0,0,1,0,0,-1,0,1,0,0,-1,0,1,0,0,-1,0,0};
priority_queue<node>q;
node beg,end;
beg.x=x1;
beg.y=y1;
beg.z=z1;
beg.step=0;
q.push(beg);
vis[x1][y1][z1]=1;
while(!q.empty())
{
end=q.top();
q.pop();
if(end.x==x2&&end.y==y2&&end.z==z2)
{
printf("Escaped in %d minute(s).\n",end.step);
return ;
}
for(i=0;i<6;i++)
{
beg.x=end.x+move[i][0];
beg.y=end.y+move[i][1];
beg.z=end.z+move[i][2];
if(!vis[beg.x][beg.y][beg.z]&&0<=beg.x&&beg.x<n&&0<=beg.y&&beg.y<m&&beg.z>=0&&beg.z<k&&map[beg.x][beg.y][beg.z]!='#')
{
map[beg.x][beg.y][beg.z]='#';
beg.step=end.step+1;
q.push(beg);
}
}
}
printf("Trapped!\n");
}
int main()
{
int i,j,t,s;
while(scanf("%d%d%d",&n,&m,&k)&&n!=0&&m!=0&&k!=0)
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%s",map[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
for(t=0;t<k;t++)
{
if(map[i][j][t]=='S')
{
x1=i;y1=j;z1=t;
}
if(map[i][j][t]=='E')
{
x2=i;y2=j;z2=t;
}
}
}
}
memset(vis,0,sizeof(vis));
bfs();
}
return 0;
}

  

最新文章

  1. FacadePattern(门面模式)
  2. 改写js原装的alert样式
  3. Type.GetType()反射另外项目中的类时返回null的解决方法
  4. JS运动从入门到精髓!哈哈
  5. WPF/MVVM 快速开始指南(译)(转)
  6. 在Windows程序中启用console输出-2016.01.04
  7. notepad 如何同时选中同一列的数据 Alt
  8. 下载好一个android软件之后,怎样自动提示安装?
  9. WebFetch 是无依赖极简网页爬取组件
  10. github 教程
  11. css form表单样式清除
  12. java注释中使用注解@see
  13. 关于C++中char 型变量的地址输出
  14. ubuntu的应用程序哪里找
  15. PGM:不完备数据的参数估计
  16. python做量化交易干货分享
  17. FPGA笔试必会知识点2—FPGA器件
  18. Eclipse常用快捷键--摘录他人
  19. git链接到远程github上
  20. Kaldi如何准备自己的数据

热门文章

  1. 移动端REM布局方案
  2. sql日期函数
  3. linux下 链接 sqlserver数据库 驱动的安装
  4. yii学习随感
  5. POJ 2442 Sequence 优先队列
  6. windows 远程桌面连接ubuntu xrdp 只看到墙纸其他什么都没有
  7. leetcode 第五题 Longest Palindromic Substring (java)
  8. [原博客] BZOJ 2725 : [Violet 6]故乡的梦
  9. 中断服务程序(Interrupt Service Routines,ISR)注意事项
  10. 系统调用与API的区别