POJ2251 Dungeon Master BFS基础
来源:互联网 发布:淘宝客三段式pid 编辑:程序博客网 时间:2024/06/01 07:36
题解:
求最短逃离迷宫时间,显然BFS,不过只是从前后左右变成了上下前后左右六个方向。
代码
#include <cstdio>#include <queue>#include <cstring>#include <iostream>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <string>#include <set>#include <ctime>#include <cmath>#include <cctype>using namespace std;#define MAX 100000#define LL long longint cas=1,T;int l,m,n;char mapp[35][35][35];int vis[35][35][35];int dx[]={1,-1,0,0,0,0};int dy[]={0,0,1,-1,0,0};int dz[]={0,0,0,0,1,-1};int to_dir[6][3]={{0,-1,0},{0,0,1},{0,1,0},{0,0,-1},{1,0,0},{-1,0,0}};bool check(int x,int y,int h){ if (x<0 || x >= n || y<0 ||y>=m||h<0||h>=l||mapp[h][x][y]=='#'|| vis[h][x][y]) return false; else return true;}struct Node{ int x; int y; int h; int step;};queue<Node> que;int main(){ while (scanf("%d%d%d",&l,&n,&m)) { Node s,e,t; if (n==0) break; for (int i = 0;i<l;i++) for (int j = 0;j<n;j++) { scanf("%s",&mapp[i][j]); for (int k=0;k<m;k++) { if (mapp[i][j][k]=='S') { s.h=i; s.x=j; s.y=k; s.step=0; vis[i][j][k]=1; } if (mapp[i][j][k]=='E') { e.h=i; e.x=j; e.y=k; e.step=0; } } } int flag = 0; while (!que.empty()) que.pop(); que.push(s); while (!que.empty()) { t=que.front(); que.pop(); if (t.x==e.x && t.y==e.y&&t.h==e.h) { flag = 1; printf("Escaped in %d minute(s).\n",t.step); break; } for (int i = 0;i<6;i++) { Node q = t; q.x +=to_dir[i][0]; q.y +=to_dir[i][1]; q.h +=to_dir[i][2]; if (!check(q.x,q.y,q.h)) continue; q.step++; vis[q.h][q.x][q.y]=1; que.push(q); } } if (!flag) { printf("Trapped!\n"); } memset(mapp,0,sizeof(mapp)); memset(vis,0,sizeof(vis)); } //freopen("in","r",stdin); //scanf("%d",&T); //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); return 0;}
0 0
- POJ2251 Dungeon Master BFS基础
- poj2251 Dungeon Master (BFS)
- Dungeon Master(poj2251,bfs)
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master bfs
- POJ2251:Dungeon Master(BFS)
- poj2251 Dungeon Master(BFS)
- POJ2251 Dungeon Master BFS
- [bfs]poj2251 Dungeon Master
- poj2251 dungeon master【BFS】~
- POJ2251 Dungeon Master(bfs)
- POJ2251 Dungeon Master(BFS)
- POJ2251-Dungeon Master-BFS
- 【POJ2251】Dungeon Master(bfs)
- poj2251-bfs- Dungeon Master
- POJ2251 Dungeon Master 【BFS】
- POJ2251:Dungeon Master(BFS)
- Dungeon Master(poj2251,bfs)
- js判断安卓、ios、还是pc端
- Hadoop 2.0 – HA功能中ZKFC对NN状态的控制
- python CSV模块使用笔记
- HttpUrlConnection
- winSCP无法连接Linux
- POJ2251 Dungeon Master BFS基础
- 发传单的人
- 集合 collection
- LeetCode 235:Lowest Common Ancestor of a Binary Search Tree
- minicom 工具使用
- Nuget如何管理我们的类库?
- opencv 3.0 vs 2013
- Servlet之运行机制,细节
- 面试题汇总