POJ-2251三维bfs
来源:互联网 发布:淘宝充流量不能退款吗 编辑:程序博客网 时间:2024/06/05 23:22
///题意大概讲的就是说 从一个点走到另一个点的最短距离,很巧妙的是这是一个三维的立体平面,其实都一样;///这个应该就是很土鳖的三维bfs,有坑待填;(细节下面走一波)#include<cstdio>#include<cstring>#include<queue>using namespace std;struct node{int x,y,z,step;};///三个方向,步数;int dx[6]={-1,1,0,0,0,0};int dy[6]={0,0,1,-1,0,0};int dz[6]={0,0,0,0,1,-1};///六个方向;int sx,sy,sz,ex,ey,ez;///记录起始点和终点;int l,r,c;char mmp[31][31][31];bool vis[31][31][31];///记录三维平面下的点的走过的情况int bfs(){ node now,next;///记录当前状态和下一个状态 queue<node>Q; now.x=sx,now.y=sy,now.z=sz,now.step=0; vis[sx][sy][sz]=1; Q.push(now);///先将最原始的状态进入队列; while(!Q.empty()) { now=Q.front(),Q.pop(); ///拿当前状态队列情况出来搞事情,看当前位置和下一个位置的关系; if(now.x==ex&&now.y==ey&&now.z==ez) return now.step;///开车到终点站就要停车了; for(int i=0;i<6;i++) { int x=now.x+dx[i]; int y=now.y+dy[i]; int z=now.z+dz[i]; ///这个是真的被坑惨了 ,原来的写法就直接后面的赋值给next,看了半天才发现了;然后无情的给了我几个WA,美滋滋; if(x>=0&&x<l&&y>=0&&y<r&&z>=0&&z<=c&&!vis[x][y][z]&&mmp[x][y][z]!='#') { vis[x][y][z]=1; next.x=x,next.y=y,next.z=z,next.step=now.step+1; Q.push(next);///将下一个队列的状态进队; } } } return 0;}int main(){ while(scanf("%d %d %d",&l,&r,&c),l||r||c) { ///这个输入是真的骚,给的样例中间居然有空格,搞得我土鳖似的一个字符一个字符的输入; ///不过后来为scanf("%s",mmp[i][j]);花式过不了; getchar(); for(int i=0;i<l;i++) { for(int j=0;j<r;j++) { for(int k=0;k<c;k++) { scanf("%c",&mmp[i][j][k]); if(mmp[i][j][k]=='S') {sx=i,sy=j,sz=k;} else if(mmp[i][j][k]=='E') {ex=i,ey=j,ez=k;} } getchar(); } getchar(); } memset(vis,0,sizeof(vis)); int ans=bfs(); if(!ans) printf("Trapped!\n"); else printf("Escaped in %d minute(s).\n",ans); } return 0;}
阅读全文
0 0
- poj 2251 三维BFS
- POJ-2251三维bfs
- poj 2251 三维BFS 无坑点
- POJ 2251 (三维迷宫问题) DFS /BFS
- POJ 2251 Dungeon Master (三维BFS)
- POJ 2251:Dungeon Master(三维BFS)
- POJ 2251 Dungeon Master (三维迷宫 BFS)
- POJ 2251 Dungeon Master(三维BFS)
- poj 2251 Dungeon Master 三维bfs
- poj 2251 Dungeon Master(三维BFS)(中等)
- poj 2251 Dungeon Master(BFS三维)
- POJ 2251 Dungeon Master(三维bfs)
- POJ 2251 Dungeon Master(三维bfs)
- <三维BFS搜索> POJ 2251 Dungeon Master
- POJ 2251:Dungeon Master(三维BFS)
- POJ 2251 Dungeon Master(三维BFS)
- POJ 2251 (BFS 简单三维迷宫)
- POJ 2251 Dungeon Master 三维BFS
- python 利用递归实现全排列
- linux基础-修改主机名
- JS字符串常用方法说明
- Spark job, stage, task, partition相关问题
- SFP,SFP+,XFP,X2和XENPAK有可能互连吗?
- POJ-2251三维bfs
- Leetcode--Restore IP Addresses
- 项目上传到github三种情况
- java mkdir()和mkdirs()区别
- 测试浮点数和整型数之间的转换处理
- TCP/IP协议
- 【腾讯TMQ】众测实战经验小结
- 压缩打包介绍、gzip、bzip2与xz压缩工具
- linux学习第二十二篇:yum更换国内源,yum下载rpm包,源码包安装