POJ - 2251 Dungeon Master
2016-07-25 19:56
387 查看
1.题面
http://poj.org/problem?id=22512.题意
没题意3.思路
bfs搜索4.代码
/***************************************************************** > File Name: tst.cpp > Author: Uncle_Sugar > Mail: uncle_sugar@qq.com > Created Time: 2016年07月25日 星期一 18时43分23秒 *****************************************************************/ # include <cstdio> # include <cstring> # include <cctype> # include <cmath> # include <cstdlib> # include <climits> # include <iostream> # include <iomanip> # include <set> # include <map> # include <vector> # include <stack> # include <queue> # include <algorithm> using namespace std; template<class T>void PrintArray(T* first,T* last,char delim=' '){ for (;first!=last;first++) cout << *first << (first+1==last?'\n':delim); } const int debug = 1; const int size = 10 + 30; const int INF = INT_MAX>>1; typedef long long ll; char g[size][size][size]; int vis[size][size][size]; int l,r,c; int dx[6] = {0,0,0,0,1,-1}; int dy[6] = {0,0,1,-1,0,0}; int dz[6] = {1,-1,0,0,0,0}; struct Coord{ int x,y,z; Coord(){} Coord(int _x,int _y,int _z):x(_x),y(_y),z(_z){} }coord[size]; Coord s,e; bool inrange(int x,int y,int z){ return x<l&&x>=0&&y<r&&y>=0&&z<c&&z>=0; } int main() { std::ios::sync_with_stdio(false);cin.tie(0); int i,j,k; queue<Coord> que; while (cin >> l >> r >> c){ if (l==0&&r==0&&c==0) break; while (!que.empty()) que.pop(); memset(vis,-1,sizeof(vis)); for (i=0;i<l;i++){ for (j=0;j<r;j++){ cin >> g[i][j]; for (k=0;k<c;k++){ if (g[i][j][k]=='S'){ s = Coord(i,j,k); g[i][j][k] = '.'; } if (g[i][j][k]=='E'){ e = Coord(i,j,k); g[i][j][k] = '.'; } } } } que.push(s); vis[s.x][s.y][s.z] = 0; while (!que.empty()){ Coord T = que.front();que.pop(); for (i=0;i<6;i++){ int nx = T.x + dx[i]; int ny = T.y + dy[i]; int nz = T.z + dz[i]; if (inrange(nx,ny,nz)&&g[nx][ny][nz]!='#'&&vis[nx][ny][nz]==-1){ vis[nx][ny][nz] = vis[T.x][T.y][T.z] + 1; que.push(Coord(nx,ny,nz)); } } if (vis[e.x][e.y][e.z]!=-1) break; } if (vis[e.x][e.y][e.z]!=-1) cout << "Escaped in " << vis[e.x][e.y][e.z] << " minute(s)." << endl; else cout << "Trapped!" << endl; } return 0; }
相关文章推荐
- **PDO** php_mysql更新 删除 & API
- bzoj 4500: 矩阵
- 高德地图
- 【HDU】3253 - The kth great number(STL,队列)
- java的输入输出,操控mongodb
- HDU_3999_二叉排序树
- PyGobject(三)基础篇
- PYTHON_IN_ML
- 本地获取tomcat服务器部署路径,但真实服务器获取tomcat部署路径报错
- html5解决大文件断点续传
- linux下so动态库一些不为人知的秘密(上)
- mysql性能测试-tpcc
- RF Analyzer for Android 安卓平台连接HackRF的App
- Python初级简易爬虫
- android五种进程
- 高德Titus
- HDU 5551 Huatuo's Medicine(水题)
- java的变量
- 2016年最新|淘宝活动报名入口大全
- 【SSOJ】物品选取 (pack)