zoj 1940 Dungeon Master
来源:互联网 发布:nginx log 路径 编辑:程序博客网 时间:2024/06/03 12:29
没什么好说的,bfs搜索
#include <iostream>#include <cstdio>#include <queue>#include <cstring>using namespace std;#define N 33int n;bool used[N][N][N];int next_step[]={0,0,1,0,1,0,1,0,0,0,0,-1,0,-1,0,-1,0,0};char map[N][N][N];int l,r,c;struct node{ int x; int y; int z; int step; node(int xx,int yy,int zz,int sstep = 0):x(xx),y(yy),z(zz),step(sstep){} node(){x = 0;y = 0; z = 0; step = 0;} node(const node & rhs) { x = rhs.x; y = rhs.y; z = rhs.z; step = rhs.step; } bool operator<(const node & rhs)const{ return step>rhs.step; }};void setnode(node &lhs,int x,int y,int z,int step = 0){ lhs.x = x; lhs.y = y; lhs.z = z; lhs.step = step;}void setnode(node &lhs,node& rhs){ lhs.x = rhs.x; lhs.y = rhs.y; lhs.z = rhs.z; lhs.step = rhs.step;}bool checknode(node& lhs){ return lhs.x>=0 && lhs.x<l && lhs.y>=0 && lhs.y<r && lhs.z>=0 && lhs.z<c;}bool bfs(node start){ priority_queue<node> que; while (!que.empty()) que.pop(); que.push(start); used[start.x][start.y][start.z] = true; while(!que.empty()){ node next(que.top()); que.pop(); next.step = next.step+1; for (int i=0;i<18;i+=3){ next.x += next_step[i]; next.y += next_step[i+1]; next.z += next_step[i+2]; if (checknode(next)){ if (!used[next.x][next.y][next.z]){ used[next.x][next.y][next.z] = true; if (map[next.x][next.y][next.z]!='#'){ if (map[next.x][next.y][next.z]=='.'){ que.push(next); }else{ printf("Escaped in %d minute(s).\n", next.step); return true; } } } } next.x -= next_step[i]; next.y -= next_step[i+1]; next.z -= next_step[i+2]; } } return false;}int main(){ while(scanf("%d %d %d",&l,&r,&c)){ memset(used,0,sizeof(used)); if (l==r&&l==c&&l==0) break; int sx,sy,sz; for (int i=0;i<l;i++){ for (int j=0;j<r;j++){ for (int k = 0;k<c;k++){ while(scanf("%c",&map[i][j][k])&&(map[i][j][k]=='\n'||map[i][j][k]==' ')); if (map[i][j][k]=='S') { sx =i;sy =j;sz =k; } } } } node start; start.x = sx; start.y = sy; start.z = sz; start.step = 0; if (!bfs(start)) printf("Trapped!\n"); } return 0;}
- ZOJ 1940 Dungeon Master
- ZOJ 1940 Dungeon Master
- zoj 1940 Dungeon Master
- zoj - 1940 - Dungeon Master
- zoj 1940 Dungeon Master
- zoj 1940 Dungeon Master
- ZOJ 1940 Dungeon Master
- ZOJ 1940 Dungeon Master
- ZOJ 1940 Dungeon Master
- zoj 1940 Dungeon Master
- ZOJ 1940 Dungeon Master 【BFS】
- zoj 1940 Dungeon Master(BFS)
- ZOJ 1940 Dungeon Master bfs
- zoj 1940 || poj 2251 Dungeon Master
- ZOJ Problem Set - 1940 Dungeon Master
- zoj 1940 || poj 2251 Dungeon Master(bfs)
- NYOJ 353 3D dungeon + zoj 1940 Dungeon Master
- ZOJ 1940 Dungeon Master (三维广搜)
- nginx读取文件代码流程
- linux如何查找一个结构体的原始定义
- MPlayer软件研究篇(一)──输出驱动
- 京东快递开接外单偏平台商户
- Eclipse快捷键小结
- zoj 1940 Dungeon Master
- QEMU1.3.0的源码分析三:user model之linux
- 深入理解typedef
- JAVA面试题之线程
- asp.netmvc3 取消页面缓存
- 跨平台的 iOS,Android 在线游戏或应用如何实现?
- margin,border,padding,content
- 页面滑动切换(类Launcher滑动屏幕实现)
- Android Audio 数据流详解