poj2251 Dungeon Master(B)
来源:互联网 发布:剑侠情缘网络单机版 编辑:程序博客网 时间:2024/06/10 17:03
题意:你被困在三维空间中,给你高宽长和地图,问最少走几步才能走出迷宫 #是障碍不能走 .是空地可以走
思路:因为是求最少步数,显然是一道广搜的题目。用pair来存储坐标,然后用队列来进行广搜。
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<queue>using namespace std;#define maxn 40typedef pair<int,pair<int,int> >pii;//分别指的是z,x,y轴的坐标#define P(a,b,c) make_pair(a,make_pair(b,c))//根据z,x,y三点制作一个pairint vis[maxn][maxn][maxn];char maps[maxn][maxn][maxn];//三维分别对应 z x yint x,y,z;//三维坐标int sx,sy,sz,ex,ey,ez;int go[6][3]={{0,0,1},{0,0,-1},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0}};//走的6个方向int num[maxn][maxn][maxn];//记录到达每个点的最小步数void bfs(int a,int b,int c){ queue<pii>s; pii p; s.push(P(a,b,c)); vis[c][a][b]=true; while(!s.empty()) { p=s.front(); s.pop(); if(p.first==ex&&p.second.first==ey&&p.second.second==ez) { printf("Escaped in %d minute(s).\n",num[ez][ex][ey]); return; } for(int i=0;i<6;i++)//六个方向的试探 { int fx=p.first+go[i][0]; int fy=p.second.first+go[i][1]; int fz=p.second.second+go[i][2]; if(fx>=0&&fx<x&&fy>=0&&fy<y&&fz>=0&&fz<z) { if(maps[fz][fx][fy]!='#'&&!vis[fz][fx][fy]) { num[fz][fx][fy]=num[p.second.second][p.first][p.second.first]+1; vis[fz][fx][fy]=true; s.push(P(fx,fy,fz)); } } } } printf("Trapped!\n"); return ;}int main(){ while(~scanf("%d%d%d",&z,&x,&y)) { if(x==0&&y==0&&z==0)break; memset(vis,false,sizeof vis); memset(num,0,sizeof num); for(int i=0;i<z;i++)//输入 初始化 { for(int j=0;j<x;j++) { scanf("%s",&maps[i][j]); for(int k=0;k<y;k++) { if(maps[i][j][k]=='S') { sx=j,sy=k,sz=i; } else if(maps[i][j][k]=='E') { ex=j,ey=k,ez=i; } } } } bfs(sx,sy,sz); } return 0;}
阅读全文
0 0
- poj2251 Dungeon Master(B)
- Dungeon Master(poj2251,bfs)
- poj2251 Dungeon Master (BFS)
- POJ2251 Dungeon Master kuangbin-搜索入门-B
- poj2251——Dungeon Master(BFS)
- POJ2251 Dungeon Master (简单搜索)
- POJ2251:Dungeon Master(三维迷宫)
- poj2251 Dungeon Master(三维bfs)
- POJ2251 Dungeon Master
- POJ2251 Dungeon Master
- poj2251 Dungeon Master (BFS)
- poj2251 - Dungeon Master
- poj2251 Dungeon Master
- POJ2251:Dungeon Master
- Dungeon Master(poj2251,bfs)
- Dungeon Master(poj2251)
- poj2251 Dungeon Master
- POJ2251:Dungeon Master(BFS)
- 局域网映射的几种方式
- 2017年一级消防工程师高薪就业
- 1030. Travel Plan (30)
- JavaSE阶段1_抽象类和接口
- redis 缓存失效原理
- poj2251 Dungeon Master(B)
- 51单片机自动循迹小车
- 湖南省第十一届大学生计算机程序设计竞赛—大还是小?
- 数据库索引的优缺点
- 白盒测试和黑盒测试_项目中的测试
- JavaSE阶段1_面向对象封装
- PHP调用存储过程失败(没有执行到)--mysql_error()--can't return a result set in the given context
- Microsoft Excel 不能访问文件“ 文件名称或路径不存在。 • 文件正被其他程序使用。 • 您正要保存的工作簿与当前打开的工作簿同名。
- 什么时候应用“缓存”,JVM共享缓存和独立缓存区别?