UVA - 532 Dungeon Master
来源:互联网 发布:excel2007数据库驱动 编辑:程序博客网 时间:2024/06/08 08:08
题目大意:逃出地牢。L 层 长 R 宽 C,从 S 走到 E 要移动几次(秒),无法逃出输出 Trapped!
解题思路:. 可走,# 不能走,化为 0 1,0 可走 1 不可走,走过的位置标记为 1。仿照上一题移动骑士UVA - 439 Knight Moves ,移动方式不一样而已,可以在三维平面上下层移动,坐标移动方式改一下,感觉没太大区别。
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int map[50][50][50];char tmp[50][50][50];int a, b, c;int L, R, C;struct queue { int x, y, z; int t; queue(int a = 0, int b = 0, int c = 0, int d = 0):x(a),y(b),z(c),t(d){}};queue q[100000];int dd[6][3] = {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,-1},{0,0,1}};int bfs(int x, int y, int z) { if (x == a && y == b && z == c) return 0; q[0] = queue(x, y, z, 0); int t1 = 0, t2 = 1; while (t1 < t2) { struct queue now = q[t1++]; for (int i = 0; i < 6; i++) { x = now.x + dd[i][0]; y = now.y + dd[i][1]; z = now.z + dd[i][2]; if (x < 0 || x >= L || y < 0 || y >= R || z < 0 || z >= C) continue; if (!map[x][y][z]) { if (x == a && y == b && z == c) return now.t+1; q[t2++] = queue(x, y, z, now.t+1); map[x][y][z] = 1; } } } return -1;}int main() { while (scanf("%d%d%d", &L, &R, &C) != EOF && L+R+C) { memset(map, 0, sizeof(map)); int x, y, z; for (int i = 0; i < L; i++) for (int j = 0; j < R; j++) scanf("%s", tmp[i][j]); for (int i = 0; i < L; i++) for (int j = 0; j < R; j++) for (int k = 0; k < C; k++) if (tmp[i][j][k] == 'S') x = i, y = j, z = k; else if (tmp[i][j][k] == 'E') a = i, b = j, c = k; else if (tmp[i][j][k] == '#') map[i][j][k] = 1; int ans = bfs(x, y, z); if (ans == -1) printf("Trapped!\n"); else printf("Escaped in %d minute(s).\n", ans); }return 0;}
0 0
- uva 532 - Dungeon Master
- uva 532 - Dungeon Master
- uva 532 - Dungeon Master
- uva 532 - Dungeon Master
- uva-532 - Dungeon Master
- UVa 532 - Dungeon Master
- UVa 532 - Dungeon Master
- UVA 532 - Dungeon Master
- UVA 532 - Dungeon Master
- UVA 532 - Dungeon Master
- UVa 532Dungeon Master
- uva 532 - Dungeon Master
- UVA 532 Dungeon Master
- uva 532 - Dungeon Master
- uva 532 Dungeon Master
- UVa 532 - Dungeon Master
- UVA 532 Dungeon Master
- UVA 532 - Dungeon Master
- C#中哈希表(HashTable)的用法详解
- 创建文件和删除文件
- Android PopupWindow详解
- Color the ball(树状数组)
- Python2.6+PyQt4.8+eric4+汉化+开发教程
- UVA - 532 Dungeon Master
- 【11】Container With Most Water
- hibernate中继承映射配置详细解析(一)
- hdoj 5442 Favorite Donut 【KMP最大表示法 后缀数组】
- CCS中不导入项目(没有)直接加载运行out文件方法
- C语言 gets()和scanf()函数的区别
- Android学习笔记——文件路径(/mnt/sdcard/...)、Uri(content://media/external/...)学习
- 【Java】 Java 内存区域和GC机制
- Arithmetic problem | 求n个直方图所含最大的矩形面积