http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=473

没什么意思

View Code

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<string.h>
 4 using namespace std;
 5 char s[31][31][31];
 6 struct node
 7 {
 8     int x,y,z,num;
 9 }q[100001];
10 int d,p,n,m,o,f[31][31][31],re[7][3] = {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};
11 void inque(int x,int y,int z)
12 {
13     d++;
14     q[d].x = x;
15     q[d].y = y;
16     q[d].z = z;
17 }
18 int judge(int x,int y,int z)
19 {
20     if(x<1||x>n||y<1||y>m||z<1||z>o)
21     return 0;
22     if(f[x][y][z])
23     return 0;
24     if(s[x][y][z]=='#')
25     return 0;
26     return 1;
27 }
28 int main()
29 {
30     int i,j,k,a[5];
31     while(scanf("%d%d%d",&n,&m,&o)!=EOF)
32     {
33         memset(f,0,sizeof(f));
34         if(n==0&&m==0&&o==0)
35         break;
36         for(i = 1; i <= n ; i++)
37         {
38            getchar();
39            for(j = 1 ; j <= m ; j++)
40            {
41                for(k = 1; k <= o ; k++)
42                {
43                     s[i][j][k] = getchar();
44                     if(s[i][j][k]=='S')
45                     {
46                         a[1] = i;
47                         a[2] = j;
48                         a[3] = k;
49                     }
50                }
51                 getchar();
52            }
53         }
54         d = 1;
55         p = 0;
56         q[d].x = a[1];
57         q[d].y = a[2];
58         q[d].z = a[3];
59         q[d].num = 0;
60         int flag = 0;
61         while(p!=d)
62         {
63             p++;
64             int tx = q[p].x;
65             int ty = q[p].y;
66             int tz = q[p].z;
67             int tnum = q[p].num;
68             if(s[tx][ty][tz]=='E')
69             {
70                 flag = 1;
71                 break;
72             }
73             for(i = 0; i < 6 ; i++)
74             {
75                 int px = tx+re[i][0];
76                 int py = ty+re[i][1];
77                 int pz = tz+re[i][2];
78                 if(judge(px,py,pz))
79                 {
80                     f[px][py][pz] = 1;
81                     inque(px,py,pz);
82                     q[d].num = q[p].num+1;
83                 }
84             }
85         }
86         if(flag)
87         printf("Escaped in %d minute(s).\n",q[p].num);
88         else
89         printf("Trapped!\n");
90     }
91     return 0;
92 }

转载于:https://www.cnblogs.com/shangyu/archive/2012/09/07/2675668.html

UVA532 - Dungeon Master(裸BFS)相关推荐

  1. UVA532 Dungeon Master

    问题链接:UVA532 Dungeon Master. 题意简述:三维空间地牢(迷宫),每个点由'.'(可以经过).'#'(墙).'S'(起点)和'E'(终点)组成.移动方向有上.下.左.右.前和后6 ...

  2. Dungeon Master(poj2251,bfs)

    http://poj.org/problem?id=2251 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15203 Dun ...

  3. Dungeon Master题解bfs

    Dungeon Master 题面翻译 题目描述 输入格式 输出格式 样例 #1 样例输入 #1 样例输出 #1 题解思路及TIME EXCEEDED问题 题解 超时题解(个人觉得没问题) 题面翻译 ...

  4. (POJ - 2251)Dungeon Master(bfs)

    题目链接:2251 -- Dungeon Master (poj.org) 这是一个典型的bfs迷宫问题,只不过是三维的,唯一需要注意的就是输入要用cin,不要用scanf,因为有换行,其他没什么了, ...

  5. Dungeon Master(bfs)广度优先搜索

    描述 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of ...

  6. Dungeon Master 三维BFS

    三维BFS DungeonMasterDungeon\ MasterDungeon Master 跟二维没啥区别,就是方向多了几个,但在写的过程中出的bugbugbug还是蛮多的,所以记录一下吧! # ...

  7. poj 2251 Dungeon Master (三维bfs)

    http://poj.org/problem?id=2251 简单bfs,只不过是三维的... 唯一的坑点在输出上... Escaped in %d minute(s) 这意思是答案为1输出minut ...

  8. pku 2251 Dungeon Master 基本BFS

    用了两种方式, 一种stl队列,一种自己实现的队列,事实证明stl就是好呀. stl万岁. #include <iostream> #include <queue> using ...

  9. poj-2251 Dungeon Master【bfs】

    很基础的一道bfs /*这题是一个三维的迷宫题目,其中用'.'表示空地,'#'表示障碍物,'S'表示起点,'E'表示终点, 求从起点到终点的最小移动次数,解法和二维的类似, 只是在行动时除了东南西北移 ...

最新文章

  1. 【ZooKeeper Notes 9】ZooKeepr日志清理
  2. cpp加密php,常用的数据加密规则算法(php包含MD5和RSA)
  3. RabbitMQ安装方法 安装完成已验证方法步骤可行性
  4. MM(Majorize-Minimization, Minorize-Maximization)优化方法
  5. apicloud手机查看效果
  6. P4884-多少个1?【BSGS】
  7. 怎么测试服务器端口是否对外开放_12个经典性能测试人员面试题
  8. VB中Unload、END、Hide的区别
  9. 第七周 linux加载和启动一个可执行程序
  10. 本地html调试java接口_solr源码通过idea进行本地调试
  11. iOS开发--获取时间
  12. 无盘工作站与VMware View虚拟桌面对比
  13. python中http_Python中的HTTP错误
  14. Python获取基金收益计算
  15. 用手机玩转GIS!这些你常用的GIS软件竟然都有手机版
  16. 小程序根据国外经纬度显示地图
  17. 10649物联卡查询, 10649物联卡官网
  18. Linux whoami和who am i命令用法和区别
  19. 算法1—线性规划和非线性规划
  20. 酸菜鱼用什么鱼最好吃

热门文章

  1. 功能强大的滚动播放插件JQ-Slide
  2. 站点安全预警,建议大家多重禁止load_file函数!
  3. 转:V.I. Arnold 论数学教育
  4. javaScript原型及继承
  5. 记一次synchronized锁字符串引发的坑兼再谈Java字符串
  6. [CareerCup] 13.10 Allocate a 2D Array 分配一个二维数组
  7. POJ 3624 Charm Bracelet
  8. 全屏显示的包含webview的页面中弹出的软键盘覆盖输入框的问题
  9. Latex应用和资源
  10. 国内第一本项目管理的实践书籍——《IT项目管理那些事儿》