POJ_2251_Dungeon Master
2010-06-22 12:42
316 查看
////三维迷宫求最短路径,BFS,三维的状态空间 ///提交WA两次,一次忘记将栈清空,一次忘记把本地测试的语句删掉 #include<stdio.h> #include<string.h> #include<queue> using namespace std; char dungeon[35][35][35]; int f[35][35][35]; int dr[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}}; int l,r,c; queue<int> q; int bfs(int a,int b,int d) { memset(f,-1,sizeof(f)); f[a][b][d]=0; int i,j,k; q.push(a); q.push(b); q.push(d); while(!q.empty()) { int m,n,p; m=q.front();q.pop(); n=q.front();q.pop(); p=q.front();q.pop(); for(i=0;i<6;i++) { int x,y,z; x=m+dr[i][0]; y=n+dr[i][1]; z=p+dr[i][2]; if(x<0||x>=l) continue; if(y<0||y>=r) continue; if(z<0||z>=c) continue; if(dungeon[x][y][z]=='.') { if(f[x][y][z]==-1) { f[x][y][z]=f[m] [p]+1; q.push(x);q.push(y);q.push(z); } } if(dungeon[x][y][z]=='E') { f[x][y][z]=f[m] [p]+1; return f[x][y][z]; } } } return 0; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while(scanf("%d%d%d",&l,&r,&c)==3) { if(!l&&!r&&!c) break; int i,j,k,t=0; for(i=0;i<l;i++) { for(j=0;j<r;j++) scanf("%s",dungeon[i][j]); } for(i=0;i<l;i++) { for(j=0;j<r;j++) { for(k=0;k<c;k++) { if(dungeon[i][j][k]=='S') { t=1; break; } } if(t)break; } if(t)break; } k=bfs(i,j,k); if(k) printf("Escaped in %d minute(s)./n",k); else printf("Trapped!/n"); while(!q.empty()) q.pop(); } }
相关文章推荐
- poj 2251 Dungeon Master
- POJ 2251 - Dungeon Master
- poj--2251--Dungeon Master
- POJ 2251 Dungeon Master【BFS】
- POJ 2251 Dungeon Master 比较有趣的三维迷宫bfs搜索路径
- POJ 2251 Dungeon Master
- POJ 2251 Dungeon Master
- poj 2251 Dungeon Master
- POJ 2251 Dungeon Master(3维BFS)
- POJ 2251 Dungeon Master (BFS)
- POJ 2251 Dungeon Master
- poj 2251 Dungeon Master(BFS)
- POJ:2251 Dungeon Master(广搜)
- POJ-2251 Dungeon Master(BFS)
- poj2251 Dungeon Master(三维bfs)
- POJ 2251 Dungeon Master(三维bfs)
- POJ2251 Dungeon Master(搜索BFS)
- POJ 2251 Dungeon Master(BFS)
- POJ 2251 Dungeon Master 简单的三维bfs
- POJ 2251 Dungeon Master