这道题的题意简单来说:就是在3D迷宫里找出口,也就是三维地图,需要用到三维数组

由于本人写代码极易出错,所以在输入三维数组的时候修改了c(column,即列)的值,重复定义了没看到==,后面改成定义成全局变量就没问题了=

除去粗心大意,这道题也可说是模板题了

这道题的代码dfs部分,写得比较清晰,比较适合初学者理解,因为我也是初学者==,感觉整理的还可哈哈hh~~

好了不多说,上代码叭

 

附上一张谷歌翻译:

 DFS搜索法:

  1 #include<iostream>
2 #include<queue>
3 #include<stdio.h>
4 #include<string.h>
5 using namespace std;
6
7 int l,r,c,vis[35][35][35];
8 char mp[35][35][35];
9
10
11 int fx[6]={1,0,-1,0,0,0};
12 int fy[6]={0,1,0,-1,0,0};
13 int fz[6]={0,0,0,0,1,-1};
14
15 struct node
16 {
17 int x,y,z;
18 int ant;
19 }now,next,s,e;
20
21 bool check(int x,int y,int z)
22 {
23 if(mp[x][y][z]!='#' && !vis[x][y][z] && x>=0 && x<l && y>=0 && y<r && z>=0 && z<c)
24 return 1;
25 return 0;
26 }
27
28 void bfs()
29 {
30 queue<node> q;
31 q.push(s);
32 while(q.size())
33 {
34 now=q.front();
35 q.pop();
36 // if(now.x==e.x && now.y==e.y && now.z==e.z)
37 if(mp[now.x][now.y][now.z]=='E') //找到终点E终止
38 {
39 return ;
40 }
41 else
42 {
43 for(int i=0;i<6;i++)
44 {
45 next.x = now.x+fx[i];//now.x替换了x
46 next.y = now.y+fy[i];
47 next.z = now.z+fz[i];
48 if(check(next.x,next.y,next.z))
49 {
50 vis[next.x][next.y][next.z]=1;
51 next.ant=now.ant+1;
52 q.push(next);
53 }
54 }
55 }
56 }
57 }
58
59 int main()
60 {
61 ios_base::sync_with_stdio(false);
62 cin.tie(0);
63
64 while(cin>>l>>r>>c && l+r+c)
65 {
66 memset(vis,0,sizeof(vis));
67 memset(mp,0,sizeof(mp));
68 for(int i=0;i<l;i++)
69 {
70 for(int j=0;j<r;j++)
71 {
72 for(int k=0;k<c;k++)
73 {
74 cin>>mp[i][j][k];
75 if(mp[i][j][k]=='S')
76 {
77 s.x=i;
78 s.y=j;
79 s.z=k;
80 s.ant=0;//直接存入全局变量的结构体
81 }
82 if(mp[i][j][k]=='E')
83 {
84 e.x=i;
85 e.y=j;
86 e.z=k;
87 }
88 }
89 }
90 }
91 vis[s.x][s.y][s.z]=1;
92 bfs();//找路
93 if(now.ant)
94 {
95 cout<<"Escaped in "<<now.ant<<" minute(s)."<<endl;
96 }
97 else
98 {
99 cout<<"Trapped!"<<endl;
100 }
101 }
102 return 0;
103 }

/*都在注释里咯,第一次多指教了~~*/

**

Dungeon Master 题解的更多相关文章

  1. POJ P2251 Dungeon Master 题解

    深搜,只不过是三维的. #include<iostream> #include<cstring> #include<cstdio> #include<algo ...

  2. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  3. POJ:Dungeon Master(三维bfs模板题)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16748   Accepted: 6522 D ...

  4. POJ2251 Dungeon Master —— BFS

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  5. 棋盘问题(DFS)& Dungeon Master (BFS)

    1棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的 ...

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

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

  7. poj 2251 Dungeon Master

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

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

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

  9. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  10. UVa532 Dungeon Master 三维迷宫

        学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时)   #i ...

随机推荐

  1. 【一个构想】pull方式获取expoter上的数据,如何更加精简?

    作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu 公众号:一本正经的瞎扯 背景 已知:在prometheus中,每个业务节点通过prometheu ...

  2. CCFLOW源码解读系列01-----发起流程

    1.发起流程 发起流程时主要做了两件事:一是写入业务数据表,二是新建一条审批流程记录. 发起流程的方法 public static Int64 Node_CreateStartNodeWork(str ...

  3. 主动学习(Active Learning)简介综述汇总以及主流技术方案

    0.引言 在机器学习(Machine learning)领域,监督学习(Supervised learning).非监督学习(Unsupervised learning)以及半监督学习(Semi-su ...

  4. C# 使用正则表达式

    在C#中,可以使用正则表达式来处理文本字符串.正则表达式是一种特殊的文本模式,用于匹配和搜索字符串.它可以识别特定模式,如邮箱地址.电话号码.网址等.正则表达式是C#中常用的一种文本处理技术,使用它可 ...

  5. C++小项目|2022期末大作业

    前言 那么这里博主先安利一下一些干货满满的专栏啦! 手撕数据结构https://blog.csdn.net/yu_cblog/category_11490888.html?spm=1001.2014. ...

  6. Program文件的作用

    Program.cs文件分析 Program.cs文件是至关重要的一个文件,它包含应用程序启动的代码,还可以配置所需要的服务和应用管道的中间件. 需要掌握: 6.0版本前后生成的Program.cs文 ...

  7. 一文详解应用安全防护ESAPI

    本文分享自华为云社区<应用安全防护ESAPI>,作者: Uncle_Tom. 1. ESAPI 简介 OWASP Enterprise Security API (ESAPI)是一个免费. ...

  8. Go语言核心36讲(Go语言实战与应用十)--学习笔记

    32 | context.Context类型 我们在上篇文章中讲到了sync.WaitGroup类型:一个可以帮我们实现一对多 goroutine 协作流程的同步工具. 在使用WaitGroup值的时 ...

  9. Flink-postgres-cdc实时同步报错:无法访问文件 "decoderbufs": 没有那个文件或目录

    问题描述 Caused by: org.postgresql.util.PSQLException: 错误: 无法访问文件 "decoderbufs": 没有那个文件或目录 解决办 ...

  10. Linux--top命令解释

    top命令解释 1.1 系统运行时间和平均负载: top命令的顶部显示与uptime命令相似的输出 这些字段显示: 当前时间 系统已运行的时间 当前登录用户的数量 相应最近5.10和15分钟内的平均负 ...