算法:广搜;

描述 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!

代码:

  1. #include <iostream>
  2. #include <cstring>
  3. #include <queue>
  4. #include <algorithm>
  5. #include <iomanip>
  6. #include <stdio.h>
  7. using namespace std;
  8. char ch[35][35][35];
  9. int n,m,k,x1,x2,y1,y2,z1,z2;
  10. int a[6][3]={1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1};
  11. struct dot
  12. {
  13. int x,y,z,step;
  14. } ;
  15. int cmp(int ax,int ay,int az)
  16. {
  17. if(ax>=0&&ax<n&&ay>=0&&ay<m&&az>=0&&az<k&&ch[ax][ay][az]=='.') return 1;
  18. return 0;
  19. }
  20. int bfs()
  21. {
  22. queue<dot>que;
  23. dot cur,loer;
  24. cur.x=x1;cur.y=y1;cur.z=z1;
  25. cur.step=0;
  26. ch[x1][y1][z1]='#';
  27. que.push(cur);
  28. while(que.size())
  29. {
  30. loer=que.front();
  31. que.pop();
  32. if(loer.x==x2&&loer.y==y2&&loer.z==z2)
  33. return loer.step;
  34. for(int i=0;i<6;i++)
  35. {
  36. cur=loer;
  37. cur.x+=a[i][0];
  38. cur.y+=a[i][1];
  39. cur.z+=a[i][2];
  40. if(cmp(cur.x,cur.y,cur.z))
  41. {
  42. ch[cur.x][cur.y][cur.z]='#';
  43. cur.step++;
  44. que.push(cur);
  45. }
  46. }
  47. }
  48. return -1;
  49. }
  50. int main()
  51. {
  52. int i,j,p;
  53. while(cin>>n>>m>>k&&n&&m&&k)
  54. {
  55. for(i=0;i<n;i++)
  56. {
  57. for(j=0;j<m;j++)
  58. {
  59. for(p=0;p<k;p++)
  60. {
  61. cin>>ch[i][j][p];
  62. if(ch[i][j][p]=='S')
  63. {x1=i;y1=j;z1=p;}
  64. if(ch[i][j][p]=='E')
  65. {x2=i;y2=j;z2=p;ch[i][j][p]='.';}
  66. }
  67. }
  68. }
  69. int ans=bfs();
  70. if(ans>=0) cout<<"Escaped in "<<ans<<" minute(s)."<<endl;
  71. else cout<<"Trapped!"<<endl;
  72. }
  73. return 0;
  74. }

3D dungeon的更多相关文章

  1. nyoj 353 3D dungeon

    3D dungeon 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 You are trapped in a 3D dungeon and need to find ...

  2. NYOJ353 3D dungeon 【BFS】

    3D dungeon 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 You are trapped in a 3D dungeon and need to find ...

  3. NYOJ--353--bfs+优先队列--3D dungeon

    /* Name: NYOJ--3533D dungeon Author: shen_渊 Date: 15/04/17 15:10 Description: bfs()+优先队列,队列也能做,需要开一个 ...

  4. NYOJ 353 3D dungeon 【bfs】

    题意:给你一个高L长R宽C的图形.每个坐标都能够视为一个方格.你一次能够向上.下.左,右,前,后任一方向移动一个方格, 可是不能向有#标记的方格移动. 问:从S出发能不能到达E,假设能请输出最少的移动 ...

  5. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  6. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  7. Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...

  8. Dungeon Master bfs

    time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u POJ 2251 Descriptio ...

  9. 暑假集训(1)第三弹 -----Dungeon Master(Poj2251)

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

随机推荐

  1. Node.js stream 流学习

    由于node.js 创建http 是这样的 http.createServer(function(request,response){}).listen(2000); 里面的request 就是rea ...

  2. Android 4.0 新增的显示数据集的桌面控件

    setRemoteAdapter (int viewId, Intent intent):该方法可以使用 Intent 更新 RemoteViews 中viewId 对应的组件. 上面方法的 Inte ...

  3. redis 扩展安装使用

    Redis的php客户端库非常之多, Redis推荐客户端链接是:http://redis.io/clients 推荐用phpredis,下载地址:https://github.com/nicolas ...

  4. HDU Train Problem I 1022 栈模拟

    题目大意: 给你一个n 代表有n列 火车,  第一个给你的一个字符串 代表即将进入到轨道上火车的编号顺序, 第二个字符串代表的是 火车出来之后到顺序, 分析一下就知道这,这个问题就是栈, 先进后出吗, ...

  5. List<T> 和DataTable的相互转换

    我用的将集合类转换为DataTable 的方法 /// <summary> /// 将集合类转换成DataTable /// </summary> /// <param ...

  6. UVALive 4959 Jumping monkey

    题意就是: 一个猎人在森林里捕猎. 然后有只猴子,喜欢躲树的后边,猎人看不见它 然后给出了一张图,表示有哪些树是相邻的. 数据保证任意图中两个树都可以直接或间接的到达 猎人有一个枪,每次他可以选择一颗 ...

  7. js跨域问题新方案

    只要创建一个空图片. js代码: var data = "http://localhost:8080/test?id="+id+"&content="+ ...

  8. 使用Cordova框架把Webapp封装成Hybrid App实践——Android篇

    公司没有IOS和没有安卓开发人员,前端后端都是需要自己玩前几天技术经理说有一个需求要把webapp封装成Hybrid App,现已完成.记录一下从中遇到的问题和需要用到的开发环境的配置 将Webapp ...

  9. 总结了关于PHP xss 和 SQL 注入的问题(转)

    漏洞无非这么几类,XSS.sql注入.命令执行.上传漏洞.本地包含.远程包含.权限绕过.信息泄露.cookie伪造.CSRF(跨站请求)等.这些漏洞不仅仅是针对PHP语言的,本文只是简单介绍PHP如何 ...

  10. OleDb 读取 excel

    //定义变量 _Application ExcelApp; Workbooks wbsMyBooks; _Workbook wbMyBook; Worksheets wssMysheets; _Wor ...