UVA 532 Dungeon Master
来源:互联网 发布:游戏编程软件中文版 编辑:程序博客网 时间:2024/05/20 20:45
UVA 532 Dungeon Master
题意:构造一个三维的迷宫,S代表当前位置,E代表出口,要判断能不能到出口,如果能,还要输出需要的时间(每走一步1分钟)。
思路: 这题是用到3维数组的搜索,一开始用DFS果断超过,卡了半天。坑爹。。。换BFS就过了。。。
代码:
#include <stdio.h>#include <string.h>struct fuck{ int x; int y; int z; int d;} q[28888];int d[6][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};int l, r, c;char map[35][35][35];int x, y, z;int judge;void bfs(int x, int y, int z){ memset(q, 0, sizeof(q)); int hx, hy, hz; int head = 0, rear = 1; q[0].x = x; q[0].y = y; q[0].z = z; q[0].d = 0; while (head < rear) {for (int i = 0; i < 6; i ++){ hx = q[head].x + d[i][0]; hy = q[head].y + d[i][1]; hz = q[head].z + d[i][2]; if (map[hx][hy][hz] == 'E')judge = q[head].d + 1; if (map[hx][hy][hz] == '.') {map[hx][hy][hz] = '#';q[rear].x = hx;q[rear].y = hy;q[rear].z = hz;q[rear++].d = q[head].d + 1; } }head ++; }} int main(){ while (scanf("%d%d%d", &l, &r, &c) != EOF && l && r && c) {judge = -1;getchar();memset(map, 0, sizeof(map));for (int i = 0; i <= l + 1; i ++) for (int j = 0; j <= r + 1; j ++)for (int k = 0; k <= c + 1; k ++){ map[i][j][k] = '#';}for (int i = 1; i <= l; i ++){ for (int j = 1; j <= r; j ++) {for (int k = 1; k <= c; k ++){ scanf("%c", &map[i][j][k]); if (map[i][j][k] == 'S') {x = i; y = j; z = k; }}getchar(); } getchar();}bfs(x, y, z);if (judge != -1) printf("Escaped in %d minute(s).\n", judge);else printf("Trapped!\n"); } return 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
- SRAM、DRAM、ROM、EEPROM、 NORFLASH、NANDFLASH
- 关于8583报文详解
- [HTML][手机]html5开发之viewport使用
- GPS 数据格式
- 程序员技术练级攻略
- UVA 532 Dungeon Master
- linux设备模型中的class
- 面试技巧:26个面试经典问题回答
- POJ1182_食物链_并查集
- UVA 10004 Bicoloring
- Win32学习笔记——资源使用
- Spring集成JPA(Hibernate实现)
- Java开发环境的搭建
- ExtJS的使用方法汇总(6)——工具栏和菜单