【简单搜索】POJ2251Dungeon Master
来源:互联网 发布:莎莎源码 解压密码 编辑:程序博客网 时间:2024/06/07 02:20
从起点跑到终点进行一遍BFS即可,算是很(ji)裸(chu)的BFS题目,练练手不错。
#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <queue>#define max 100using namespace std;char map[max][max][max];short vis[max][max][max];int dir[6][3] = { {0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0} };int l, r, c;int sx, sy, sfloor, ex, ey, efloor;int ans;struct node{ int floor, x, y,step;};int isture(int x, int y, int z){ if (x < 0 || x >= l || y < 0 || y >= r || z < 0 || z >= c) return 0; else if (map[x][y][z] == '#') return 0; else if (vis[x][y][z]) return 0; return 1;}int bfs(){ queue<node>q; struct node now, next; now.floor = sfloor; now.x = sx; now.y = sy; now.step = 0; while (!q.empty()) q.pop(); q.push(now); vis[sfloor][sx][sy] = 1; while (!q.empty()) { now = q.front(); q.pop(); if (now.floor == efloor&&now.x == ex&&now.y == ey) return now.step; for (int i = 0;i < 6;i++) { next.floor = now.floor + dir[i][0]; next.x = now.x + dir[i][1]; next.y = now.y + dir[i][2]; next.step = now.step + 1; if (isture(next.floor, next.x, next.y)) { vis[next.floor][next.x][next.y] = 1; q.push(next); } } } return 0;}int main(){ while (cin >> l >> r >> c, l + r + c) { for (int i = 0;i < l;i++) { for (int j = 0;j < r;j++) { cin >> map[i][j]; for (int k = 0;k < c;k++) { if (map[i][j][k] == 'S') { sfloor = i; sx = j; sy = k; } else if (map[i][j][k] == 'E') { efloor = i; ex = j; ey = k; } } } } memset(vis, 0, sizeof(vis)); ans = 0; ans = bfs(); if (ans) cout << "Escaped in " << ans << " minute(s)." << endl; else cout << "Trapped!" << endl; }}
0 0
- 【简单搜索】POJ2251Dungeon Master
- POJ2251Dungeon Master
- poj2251Dungeon Master bfs
- poj2251Dungeon Master【BFS】
- POJ2251Dungeon Master(AC)
- POJ2251Dungeon Master(bfs)
- POJ2251Dungeon Master&&nyoj523亡命逃窜
- POJ2251Dungeon Master(三维图)(BFS)
- poj2251Dungeon Master(三维bfs)
- POJ2251Dungeon Master(图搜)(三维bfs)
- POJ2251Dungeon Master(3D bfs)
- 简单搜索:Dungeon Master ()
- POJ 2251-Dungeon Master【简单搜索】
- POJ2251 Dungeon Master (简单搜索)
- uva 340 Master-Mind Hints(最简单标记搜索)
- Dungeon Master([kuangbin带你飞]专题一 简单搜索)
- Cable master (二分搜索)
- POJ 2251 Dungeon Master (kuangbin带你飞 专题一:简单搜索)
- POJ - 3984
- js实现tab栏切换效果(一)
- HDFS NFS Gateway
- 通过transfrom来修改位置.大小(缩放).旋转
- requireJS缓存问题
- 【简单搜索】POJ2251Dungeon Master
- java类初始化顺序
- 评估方法、性能度量和比较检验
- spring boot 学习(六)spring boot 各版本中使用 log4j2 记录日志
- Android各个Support Library介绍
- C语言实验——素数 (sdut oj)
- UnitySDK接入——Android篇
- 推荐系统机器学习领域大牛主页
- 301、404、200、304等HTTP状态