hdu 1253 3D bfs
来源:互联网 发布:怎么清除手机数据 编辑:程序博客网 时间:2024/05/19 19:42
题意:
3D迷宫bfs。
解析:
和之前的那个3D迷宫差不多。
代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <queue>#include <map>#define LL long long#define lson lo, mi, rt << 1#define rson mi + 1, hi, rt << 1 | 1using namespace std;const int maxn = 50 + 10;const int inf = 0x3f3f3f3f;const double eps = 1e-6;const double pi = acos(-1.0);const double ee = exp(1.0);int dir[][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};int n, m, l;int backTime;int g[maxn][maxn][maxn];int step[maxn][maxn][maxn];struct Node{ int x, y, z; Node(int _x, int _y, int _z) { x = _x; y = _y; z = _z; }};bool ok(int x, int y, int z){ if (0 <= x && x < n && 0 <= y && y < m && 0 <= z && z < l && g[x][y][z] != 1) return true; return false;}int bfs(){ memset(step, -1, sizeof(step)); queue<Node> q; step[0][0][0] = 0; q.push(Node(0, 0, 0)); while (!q.empty()) { Node now = q.front(); q.pop(); int x = now.x; int y = now.y; int z = now.z; if (x == n - 1 && y == m - 1 && z == l - 1) { return step[x][y][z]; } for (int i = 0; i < 6; i++) { int nx = x + dir[i][0]; int ny = y + dir[i][1]; int nz = z + dir[i][2]; if (ok(nx, ny, nz)) { if (step[nx][ny][nz] == -1) { step[nx][ny][nz] = step[x][y][z] + 1; if (step[nx][ny][nz] <= backTime) { q.push(Node(nx, ny, nz)); } } } } } return -1;}int main(){#ifdef LOCAL freopen("in.txt", "r", stdin);#endif // LOCAL int ncase; scanf("%d", &ncase); while (ncase--) { scanf("%d%d%d%d", &l, &n, &m, &backTime); for (int k = 0; k < l; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf("%d", &g[i][j][k]); } } } printf("%d\n", bfs()); } return 0;}
0 0
- hdu 1253 3D bfs
- POJ2251 3D地图(BFS)
- NYOJ353 3D dungeon 【BFS】
- 353 3D dungeon【bfs】
- 3D dungeon(bfs)
- uva532--3d迷宫--bfs
- hdu 1253 三维bfs
- HDU 1253(BFS)
- HDU[1253]--bfs
- hdu~1253(bfs)
- hdu 1253 bfs
- hdu 1253 bfs
- hdu 1253 bfs
- 1114 Food Cubes 3D BFS
- 1114. Food Cubes (3D bfs)
- NYOJ 353 3D dungeon 【bfs】
- nyoj 353 3D dungeon 【bfs】
- NYOJ 353--3D dungeon【水题 && BFS】
- Python 下划线(_)的用法
- 聚类分析(数据挖掘原书第三版,范明,孟小峰译)
- ls详解
- 格式转换说明符scanf,printf格式%大全/格式化输入输出
- ubuntu 使用手记!
- hdu 1253 3D bfs
- 【java学习】9.时间的概念
- B-树学习笔记
- 建立mysql与数据库连接和释放资源 工具类
- 浅谈经典排序算法系列—各种排序算法总结
- android TabHost的两种布局方式
- 在共享 DLL 中使用 MFC 出现内存泄漏
- Centos6.5下使用tcpdump抓包并用wireshark分析
- EditPlus 在线生成注册码