poj 2251 Dungeon Master 简单队列与BFS
来源:互联网 发布:2选1数据选择器原理图 编辑:程序博客网 时间:2024/06/03 20:16
唉, 啥也不想说了,这道题做了两天了 , 一直不对, 测试数据都是错的,真的很无奈,看网上的教程发现跟他们的方法一样,而且那个广搜写的也大径相同但是我的就是不对,郁闷死我了,第二天才发现是哪里出错的,本来我定义的整个一大串的东西都是在一个结构体里面的,今天在单步调试的时候才发现如果都定义在结构体里面的话会里面的字符在传递的时候是不会更新的。我也是晕的不行。唉~且行且珍惜~~~~~~~~~~
<#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<queue>#include<iostream>#include<algorithm>using namespace std;struct node{ int x, y, z,step;}p[30000];int vmapp[31][31][31];char mapp[31][31][31];int n, m,k,r;int x,y,z,ex;int ey,ez;int to[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};int check(struct node a){ if(a.x<0 || a.x>=k || a.y>=n || a.y<0 || a.z>=m || a.z<0) return 1; if(vmapp[a.x][a.y][a.z]) return 1; if(mapp[a.x][a.y][a.z]=='#') return 1; return 0;}int bfs(){ queue<node>q; int i, j; struct node a, b; memset(vmapp,0,sizeof(vmapp)); vmapp[x][y][z]=1; q.push(p[r]); while(!q.empty()) { a=q.front(); q.pop(); if(a.x==ex && a.y==ey && a.z==ez) return a.step; for(i=0;i<6;i++) { b=a; b.x=a.x+to[i][0]; b.y=a.y+to[i][1]; b.z=b.z+to[i][2]; if(check(b)) continue; vmapp[b.x][b.y][b.z]=1; b.step=a.step+1; q.push(b); } } return 0;}int main(){ int i, j,e, q,ans; while(scanf("%d%d%d",&k, &n, &m), k+n+m) { q=0; for(i=0;i<k;i++) { for(j=0;j<n;j++) { for(e=0;e<m;e++) { char c; cin>>mapp[i][j][e]; if(mapp[i][j][e]=='S') { x=i;r=q; y=j;z=e; } else if(mapp[i][j][e]=='E') { ex=i; ey=j;ez=e; } p[q].x=i; p[q].y=j; p[q].z=e; p[q].step=0; q++; } } } ans=bfs(); if(ans) printf("Escaped in %d minute(s).\n",ans); else printf("Trapped!\n"); }}
0 0
- 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)
- 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)
- 代码重构技巧
- 获取非客户区消息
- 关于APK瘦身值得分享的一些经验
- 如何将PDF转为可编辑的Word文档
- 把EXCEL用程序导入到ORACLE中(SpringMVC+MyBatis)
- poj 2251 Dungeon Master 简单队列与BFS
- 聚类 - 1 - 聚类介绍
- Java内存区域与内存溢出
- Win7 64Bit + VS2012 + openBLAS0.2.18
- Oracle学习记录整理笔记1-数据备份
- 关于对数组和指针的测试与分析OC
- hdu 5723 (最小生成树 + 树上的期望)
- 使用JMeter3.0实战之分布式并发测试以及web API接口测试
- OPENCV 3.0.0 win10 vs2013 配置