【HOJ 1448 Dungeon Master(BFS)】
来源:互联网 发布:淘宝的化州橘红假吗 编辑:程序博客网 时间:2024/06/07 17:45
原题地址:
http://acm.hit.edu.cn/hojx/showproblem/1448/
这题没什么特别的,区别就在于这个是多层的,有了思路特别好写的~;
/*Judge Status: AcceptedPID : 1448Time : 0.01sMemory : 2184KLanguage : G++Code Len. : 2548Author : Belieber_J*/#include <iostream>#include <queue>#include <stdio.h>#include <stdlib.h>#include <string.h>using namespace std;int l,r,c,i,j,k,sl,sr,sc,tl,tr,tc;char s[40][40][40];int vis[40][40][40];struct Node{ int l,r,c,step;//! level row column};int dl[6] = {0,0,0,0,1,-1};int dr[6] = {1,-1,0,0,0,0};int dc[6] = {0,0,1,-1,0,0};int direct;queue<Node>q;int bfs(int sl,int sr,int sc){ while (!q.empty()) q.pop(); memset(vis,0,sizeof(vis)); Node st; st.l = sl; st.r = sr; st.c = sc; st.step = 0; vis[sl][sr][sc] = 1; q.push(st); while (!q.empty()) { Node cur = q.front(); q.pop(); for (direct = 0; direct < 6; direct++) { Node nx; nx.l = cur.l + dl[direct]; nx.r = cur.r + dr[direct]; nx.c = cur.c + dc[direct]; nx.step = cur.step + 1; if (nx.l == tl && nx.r == tr && nx.c == tc) return nx.step; if (nx.l < 0 || nx.l >= l || nx.r < 0 || nx.r >= r || nx.c < 0 || nx.c >= c) continue; else if(vis[nx.l][nx.r][nx.c] || s[nx.l][nx.r][nx.c] == '#') continue; else { vis[nx.l][nx.r][nx.c] = 1; q.push(nx); } } } return -1;}int main(){ int cou; while (scanf("%d%d%d",&l,&r,&c) == 3 && (l || r || c)) { for (i = 0; i < l; i++) { for (j = 0; j < r; j++) { scanf("%s",s[i][j]); for (k = 0; k < c; k++) { if (s[i][j][k] == 'S') { sl = i; sr = j; sc = k; } if (s[i][j][k] == 'E') { tl = i; tr = j; tc = k; } } } } cou = bfs(sl,sr,sc); if (cou == -1) printf("Trapped!\n"); else printf("Escaped in %d minute(s).\n",cou); } return 0;}
阅读全文
0 0
- 搜索(bfs) HOJ 1448 Dungeon Master
- 【HOJ 1448 Dungeon Master(BFS)】
- Hoj 1448 Dungeon Master
- Dungeon Master(bfs)
- Dungeon Master(BFS)
- (bfs)Dungeon Master
- Dungeon Master (BFS)
- Dungeon Master(BFS)
- [hoj]Dungeon Master
- poj Dungeon Master(Bfs)
- Dungeon Master(poj2251,bfs)
- 532 - Dungeon Master(bfs)
- A - Dungeon Master(BFS)
- poj_2251 Dungeon Master(bfs)
- poj2251 Dungeon Master (BFS)
- POJ 2251 Dungeon Master (三维BFS)
- poj-2251-Dungeon Master(bfs)
- poj 2251 Dungeon Master(BFS)
- HTML学习笔记day2
- 千万不要做的RM( 恢复被rm意外删除的数据文件)
- 【JAVA】实现用户从键盘输入
- Linux(CentOs) 内存查看及合理分配
- Mastering ElasticSearch.pdf 英文原版 免费下载
- 【HOJ 1448 Dungeon Master(BFS)】
- adminLTE 教程 -5 tab
- Qt|派生类中,其他类的对象如何初始化,其他类包括基类的基类和无关类
- 蓝桥杯练习题之圆的面积
- shell脚本链接数据库导出数据
- 哪款软件可以实现基于多张二维图像的三维重建?
- javascript正则表达式
- navicat连接oracle数据库
- geowebcache发布arcgis切片