poj 2251 Dungeon Master
2015-07-05 11:24
393 查看
原题链接:http://poj.org/problem?id=2251
三维迷宫。。
三维迷宫。。
[code]#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<vector> #include<queue> #include<map> using std::cin; using std::cout; using std::endl; using std::find; using std::sort; using std::map; using std::pair; using std::queue; using std::vector; using std::multimap; #define pb(e) push_back(e) #define sz(c) (int)(c).size() #define mp(a, b) make_pair(a, b) #define all(c) (c).begin(), (c).end() #define iter(c) decltype((c).begin()) #define cls(arr,val) memset(arr,val,sizeof(arr)) #define cpresent(c, e) (find(all(c), (e)) != (c).end()) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i) const int N = 32; typedef unsigned long long ull; char G ; bool vis ; int L, R, C, Sx, Sy, Sz, Dx, Dy, Dz; const int dx[] = { -1, 1, 0, 0, 0, 0 }; const int dy[] = { 0, 0, -1, 1, 0, 0 }, dz[] = { 0, 0, 0, 0, -1, 1 }; struct Node { int x, y, z, s; Node() {} Node(int i, int j, int k, int l) :x(i), y(j), z(k), s(l) {} }; int bfs() { cls(vis, false); queue<Node> q; q.push(Node(Sx, Sy, Sz, 0)); vis[Sx][Sy][Sz] = true; while (!q.empty()) { Node t = q.front(); q.pop(); if (t.x == Dx && t.y == Dy && t.z == Dz) return t.s; rep(i, 6) { int x = t.x + dx[i], y = t.y + dy[i], z = t.z + dz[i]; if (x < 0 || x >= L || y < 0 || y >= R || z < 0 || y >= C) continue; if (vis[x][y][z] || G[x][y][z] == '#') continue; q.push(Node(x, y, z, t.s + 1)); vis[x][y][z] = true; } } return 0; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w+", stdout); #endif while (~scanf("%d %d %d", &L, &R, &C) && L + R + C) { rep(i, L) { rep(j, R) { scanf("%s", G[i][j]); rep(k, C) { if (G[i][j][k] == 'S') Sx = i, Sy = j, Sz = k; if (G[i][j][k] == 'E') Dx = i, Dy = j, Dz = k; } } } int ret = bfs(); if (!ret) puts("Trapped!"); else printf("Escaped in %d minute(s).\n", ret); } return 0; }
相关文章推荐
- Django 部署在局域网上
- 【Linux知识】server性能测试--UnixBench
- iOS开发网络篇—NSURLConnection基本使用
- android FragmentActivity+FragmentTabHost+Fragment框架布局
- javascript内存泄露
- javascript实现控制的多级下拉菜单
- gcc 4.7.0 以上版本的gcc可能存在的bug及解决方法
- 关于resetlogs
- Deep Learning for Nature Language Processing --- 第五讲
- font-size的探究
- sublime快捷方式和node.js
- 马拦过河卒(NOIP)
- NSBundle 的常用方法
- <VirtualHost *:80>配置文件
- 范围要找个时间记住
- 【原创】FltGetFileNameInformation蓝屏分析
- NSHomeDirectory(); 动态获取路径
- 建立GridView Column
- SWIG and Android
- 计算几何(转)