UVA 532 - Dungeon Master
六个方向广搜...先是knowledgetime的代码,我写了一遍能A、、、
#include <stdio.h>#include <string.h>#define Msize 29800typedef struct Dungeon{int x,y,z,d;};const int step[10][3]={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};Dungeon q[Msize]={0};int L,R,C,mat[40][40][40]={0},mins;bool vis[40][40][40]={false};int sx,sy,sz,ex,ey,ez;char s[40]={'\0'};void bfs(){int head=0,tail=1,hx,hy,hz; q[0].x=sx; q[0].y=sy; q[0].z=sz; q[0].d=0; vis[sx][sy][sz]=true;while(head<tail) {for(int i=0;i<6;i++) { hx=q[head].x+step[i][0]; hy=q[head].y+step[i][1]; hz=q[head].z+step[i][2];if(0<hx&&hx<=L && 0<hy&&hy<=R && 0<hz&&hz<=C && mat[hx][hy][hz] && !vis[hx][hy][hz]) {if(hx==ex && hy==ey && hz==ez) { mins=q[head].d+1;return; } q[tail].x=hx; q[tail].y=hy; q[tail].z=hz; q[tail++].d=q[head].d+1; vis[hx][hy][hz]=true; } } head++; }}int main(){while(scanf("%d %d %d",&L,&R,&C)==3) {if(L+R+C==0) break; getchar(); memset(mat,0,sizeof(mat)); memset(vis,false,sizeof(vis));for(int i=1;i<=L;i++)for(int j=1;j<=R;j++) { scanf("%s",s);for(int k=1;k<=C;k++)if(s[k-1]=='S') { sx=i; sy=j; sz=k; }else if(s[k-1]=='E') { ex=i; ey=j; ez=k; mat[i][j][k]=1; }else if(s[k-1]=='.') mat[i][j][k]=1; } mins=-1; bfs();if(mins<0) printf("Trapped!\n");else printf("Escaped in %d minute(s).\n",mins); }return 0;}
这个代码是我自己写的,始终过不了,莫名其妙地RE!!!
#include<cstdio>#include<cstring>#include<cstdlib>#define MAXL 40 int L, R, C, SX, SY, SZ, EX, EY, EZ;char str[MAXL];bool vis[MAXL][MAXL][MAXL];int d[MAXL][MAXL][MAXL];int qx[50000], qy[50000], qz[50000]; int dx[] = { 1, -1, 0, 0, 0, 0};int dy[] = { 0, 0, -1, 1, 0, 0};int dz[] = { 0, 0, 0, 0, 1, -1}; bool judge( int a, int b, int c){if( a < 1 || b < 1 || c < 1 || a > L || b > R || c > C || !vis[a][b][c])return false;return true;} void init(){ memset( d, -1, sizeof d); memset( vis, false, sizeof vis);for( int i = 1; i <= L; i ++) {for( int j = 1; j <= R; j ++) { scanf( "%s", str);for( int k = 1; k <= C; k ++) {if( str[k - 1] == 'S' || str[k - 1] == 'E' || str[k - 1] == '.') vis[i][j][k] = true;if( str[k - 1] == 'S') { SX = i; SY = j; SZ = k; }if( str[k - 1] == 'E') { EX = i; EY = j; EZ = k; } } } }} void bfs(){int x, y, z;int front = 0, rear = 0; d[SX][SY][SZ] = 0; qx[rear] = SX; qy[rear] = SY; qz[rear] = SZ; rear ++;while( front < rear) { x = qx[front]; y = qy[front]; z = qz[front]; front ++; vis[x][y][z] = false;if( x == EX && y == EY && z == EZ)return;for( int i = 0; i < 6; i ++) {int nx = x + dx[i];int ny = y + dy[i];int nz = z + dz[i];bool yes = judge( nx, ny, nz);if( yes) { qx[rear] = nx; qy[rear] = ny; qz[rear] = nz; rear ++; d[nx][ny][nz] = d[x][y][z] + 1; } } }} int main(){while( scanf( "%d%d%d", &L, &R, &C) == 3) { getchar();if( L + R + C == 0) break; init(); bfs();int ok = d[EX][EY][EZ];if( ok < 0) printf( "Trapped!\n");else printf( "Escaped in %d minute(s).\n", ok); }return 0;}
转载于:https://www.cnblogs.com/Yu2012/archive/2011/12/16/2290039.html
UVA 532 - Dungeon Master相关推荐
- B - Dungeon Master POJ - 2251
B - Dungeon Master POJ - 2251 题目: 逃离3D迷宫,n <=30 首先是dfs,算一下最坏情况共30层,每层有30*30的循环, 复杂度 3030*30 显然严重爆 ...
- POJ 2251 Dungeon Master(三维BFS求最短路径)
3D dungeon 时间限制: 1 Sec 内存限制: 128 MB 提交: 2 解决: 2 [提交][状态][讨论版][命题人:201506020829][Edit] [TestData] 题 ...
- 信息学奥赛一本通(1248:Dungeon Master)
1248:Dungeon Master 时间限制: 1000 ms 内存限制: 65536 KB 提交数: 8637 通过数: 3432 [题目描述] 这题是一个三维的迷宫题目 ...
- Dungeon Master 地下城大师(BFS进阶)
题目链接:2251 -- Dungeon Master 知道你看不懂题(手动滑稽):友情链接. 题意:找到从S到E的最少步数的路径,输出该步数,不过有意思的是这个类似迷宫问题不是二维的,是一个三维迷宫 ...
- Dungeon Master(地牢大师、底下城主)三维bfs
1253:Dungeon Master(地牢大师.底下城主) 要敢于变通 和普通bfs的区别,仅仅在于数组开三维+搜索方向多了上下(现在的搜索方向是 上下东南西北) bfs多组输入要记得清空队列 // ...
- Dungeon Master题解bfs
Dungeon Master 题面翻译 题目描述 输入格式 输出格式 样例 #1 样例输入 #1 样例输出 #1 题解思路及TIME EXCEEDED问题 题解 超时题解(个人觉得没问题) 题面翻译 ...
- Dungeon Master(poj2251,bfs)
http://poj.org/problem?id=2251 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15203 Dun ...
- BFS - Dungeon Master
Dungeon Master 题目链接: https://vjudge.net/problem/POJ-2251 题目: You are trapped in a 3D dungeon and nee ...
- (POJ - 2251)Dungeon Master(bfs)
题目链接:2251 -- Dungeon Master (poj.org) 这是一个典型的bfs迷宫问题,只不过是三维的,唯一需要注意的就是输入要用cin,不要用scanf,因为有换行,其他没什么了, ...
最新文章
- Android之在BaseAdapter源码中了解观察者模式
- 数据结构与算法:二分法
- python super 参数问题
- vue循环渲染子组件视图不更新问题
- pitstop插件使用说明_PDF其他及PitStop插件
- Spring系列合并
- 牛客网编程题——字符串_空格替换
- flash中物体运动基础之七---------碰撞处理
- Pandas简单写入数据到csv文件
- 简单实用的下载百度文库文档的方法
- Code For Better 谷歌开发者之声——Google Cloud谷歌云
- 11行Python代码制作聊天机器人
- 大牛教你怎么学习Java多进程,下载量瞬秒百万
- DDOS防护如何建设?
- 如何卸载干净JAVA
- 在使用集合中的contains(),要根据实际情况改写集合中对象的equals(Object obj)方法------改写List集合中equals(Object obj)的方法
- 接吻时最不想遇见的10种情况
- 【人工智能时代——Notion AI vs ChatGPT】
- 奔跑吧小子 v1.0.3 安卓版
- php是什么意思啊cf手游图片,CF手游星芒武器解析 英雄近战武器星芒分析
热门文章
- mac安装完python怎么打开-Mac OS系统如何安装python
- 自学python要到什么程度-学好深度学习,Python 得达到什么程度?
- 电脑安装python3.7说缺少-centos7:python3.7 缺少_ssl模块问题
- python和linux哪个难学-“慢”下来的 Python 要怎么竞争?
- php和python对比-PHP和Python性能比较:放弃PHP改用Python
- 学python的好处-学习python有什么好处?python强大之处在哪?
- python装饰器-python装饰器是哪个版本支持的
- python小游戏编程实例-Python实现的弹球小游戏示例
- python下载后如何使用-如何使用Python通过HTTP下载文件?
- python 基础命令-详解python常用命令行选项与环境变量