poj 2251 Dungeon Master
2016-04-05 11:28
316 查看
这道是个用个简单的宽搜或者深搜就能做出来,只需要注意有上,下,左,上一层,下一层,后共计6个方向。
难点在于读懂题意,地牢分为了n层,注意到这一点就简单了。
难点在于读懂题意,地牢分为了n层,注意到这一点就简单了。
#include <iostream> #include <queue> using namespace std; const int MAXSIZE = 300; struct coord { int x, y, z; int step; bool operator()(const coord &a, const coord &b) { return a.step > b.step; } }; char map[MAXSIZE][MAXSIZE][MAXSIZE]; int direct[6][3] = {1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,-1,0,0,1}; int main() { int i, j, k; while (true) { int a, b, c; coord start; int sum; priority_queue<coord, vector<coord>, coord> s; cin >> i >> j >> k; if (i == 0 && j == 0 && k == 0) break; for (c = 1; c <= i; c++) for (a = 1; a <= j; a++) for (b = 1; b <= k; b++) { cin >> map[c][a][b]; if (map[c][a][b] == 'S') { start.z = c; start.x = a; start.y = b; start.step = 0; } } s.push(start); map[start.z][start.x][start.y] = '#'; bool flag = false; while (!s.empty()) { coord kk = s.top(); s.pop(); for (int b = 0; b < 6; b++) { start.z = kk.z + direct[b][0]; start.x = kk.x + direct[b][1]; start.y = kk.y + direct[b][2]; if (start.z >= 1 && start.x >= 1 && start.z >= 1 && start.z <= i&&start.x <= j&&start.y <= k) { if (map[start.z][start.x][start.y] == '.') { start.step = kk.step + 1; s.push(start); map[start.z][start.x][start.y] = '#'; } else if (map[start.z][start.x][start.y] == 'E') { flag = true; sum = kk.step + 1; break; } } } if (flag) break; } if (flag) cout << "Escaped in " << sum << " minute(s)." << endl; else cout << "Trapped!" << endl; } }
相关文章推荐
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- POJ-1695-Magazine Delivery-dp
- POJ1523 SPF dfs
- POJ-1001 求高精度幂-大数乘法系列
- POJ-1003 Hangover
- POJ-1004 Financial Management
- 用单调栈解决最大连续矩形面积问题
- 2632 Crashing Robots的解决方法
- 1573 Robot Motion (简单题)
- POJ 1200 Crazy Search(简单哈希)
- 【高手回避】poj3268,一道很水的dijkstra算法题