博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[POJ 2251] Dungeon Master
阅读量:7217 次
发布时间:2019-06-29

本文共 2520 字,大约阅读时间需要 8 分钟。

题目链接:http://poj.org/problem?id=2251

注意:细心细心再细心!!

1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 7 const int maxn = 35; 8 int L,R,C; 9 bool vis[maxn][maxn][maxn];10 char maze[maxn][maxn][maxn];11 int go[6][3] = {
0,0,1,0,0,-1,0,1,0,0,-1,0,1,0,0,-1,0,0};12 struct node13 {14 int x,y,z;15 int count;16 }now,nex;17 18 bool IsOk(node s)19 {20 return (s.x>=0&&s.x
=0&&s.y
=0&&s.z
Q;26 vis[now.x][now.y][now.z]=1;27 Q.push(now);28 while(!Q.empty())29 {30 now = Q.front();31 Q.pop();32 if(maze[now.x][now.y][now.z]=='E')33 return now.count;34 for(int i=0;i<6;i++)35 {36 nex.x = now.x + go[i][0];37 nex.y = now.y + go[i][1];38 nex.z = now.z + go[i][2];39 if(IsOk(nex))40 {41 vis[nex.x][nex.y][nex.z]=1;42 nex.count = now.count + 1;43 Q.push(nex);44 }45 }46 }47 return 0;48 }49 50 int main()51 {52 while(~scanf("%d%d%d",&L,&R,&C)&&(L||R||C))53 {54 for(int i=0;i

 

复习一遍,代码和上面的稍有不同:

1 #include
2 #include
3 #include
4 using namespace std; 5 6 const int maxn = 30; 7 char maze[maxn][maxn][maxn]; 8 bool vis[maxn][maxn][maxn]; 9 int go[6][3] = {
0,0,1,0,0,-1,1,0,0,-1,0,0,0,-1,0,0,1,0};10 int l,r,c;11 int sx,sy,sz;12 struct Point13 {14 int x,y,z;15 int cnt;16 }now,nex;17 18 bool IsOk(Point s)19 {20 if(s.x<0||s.x>=l||s.y<0||s.y>=r||s.z<0||s.z>=c)21 return 0;22 else if(maze[s.x][s.y][s.z] == '#')23 return 0;24 else if(vis[s.x][s.y][s.z])25 return 0;26 else27 return 1;28 }29 int BFS()30 {31 now.x = sx;now.y = sy;now.z = sz;32 now.cnt = 0;33 vis[sx][sy][sz] = 1;34 queue
q;35 q.push(now);36 while(!q.empty())37 {38 now = q.front();39 q.pop();40 if(maze[now.x][now.y][now.z] == 'E')41 {42 return now.cnt;43 }44 for(int i=0;i<6;i++)45 {46 nex.x = now.x + go[i][0];47 nex.y = now.y + go[i][1];48 nex.z = now.z + go[i][2];49 if(IsOk(nex))50 {51 vis[nex.x][nex.y][nex.z] = 1;52 nex.cnt = now.cnt + 1;53 q.push(nex);54 }55 }56 }57 return -1;58 }59 60 int main()61 {62 while(~scanf("%d%d%d",&l,&r,&c)&&(l||r||c))63 {64 for(int i=0;i

 

转载于:https://www.cnblogs.com/youpeng/p/10245443.html

你可能感兴趣的文章
iOS开发UI篇—程序启动原理和UIApplication
查看>>
MUI 里js动态添加数字输入框后,增加、减少按钮无效
查看>>
python pip 更换国内安装源(windows)
查看>>
结对编程2后篇
查看>>
oracle exp 和 imp 数据和表结构互相独立导出导入
查看>>
iphone-common-codes-ccteam源代码 CCNSPredicate.m
查看>>
这次项目中应该注意的问题和应该保持的好习惯
查看>>
python-数据结构化与保存
查看>>
LeetCode - 551. Student Attendance Record I
查看>>
Java用户线程和守护线程
查看>>
ClassLoader类加载机制&&JVM内存管理
查看>>
Caml语句 查询分配给当前用户及当前组
查看>>
记一次源码分析
查看>>
php版本引起的const问题
查看>>
js实现60s倒计时效果
查看>>
【POJ 2176】Folding
查看>>
redis的过期策略以及内存淘汰机制
查看>>
阿牛的EOF牛肉串
查看>>
随笔2013/2/13
查看>>
笨办法32循环和列表
查看>>