标签:des style blog http color java os io strong
#include <iostream> #include <stdio.h> #include <string.h> #include <queue> using namespace std; #define maxx 45 char map[maxx][maxx][maxx]; int vis[maxx][maxx][maxx]; int dir[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}}; //int dir[6][3]= {(1,0,0),(-1,0,0),(0,1,0),(0,-1,0),(0,0,1),(0,0,-1)}; /// 这里让我WA了 无限次~~~~~~~~~~~ int l,r,c; struct node { int x,y,z; int step; }; int bfs(int si,int sj,int sk){ queue<node> q; while(!q.empty()) q.pop(); memset(vis,0,sizeof(vis)); node cur,next; cur.z=si,cur.x=sj,cur.y=sk,cur.step=0; vis[si][sj][sk]=1; q.push(cur); while(!q.empty()){ cur=q.front(); q.pop(); for(int i=0;i<6;i++){ next.z=cur.z+dir[i][0]; next.x=cur.x+dir[i][1]; next.y=cur.y+dir[i][2]; next.step=cur.step+1; if(next.z<1 || next.z>l || next.x<1 || next.x>r || next.y<1 || next.y>c || map[next.z][next.x][next.y]==‘#‘) continue; if(map[next.z][next.x][next.y]==‘E‘) return next.step; if(!vis[next.z][next.x][next.y]){ vis[next.z][next.x][next.y]=1; q.push(next); } } } return 0; } int main(){ int si,sj,sk; while(scanf("%d%d%d",&l,&r,&c),l,r,c){ for(int i=1;i<=l;i++) for(int j=1;j<=r;j++) for(int k=1;k<=c;k++){ cin>>map[i][j][k]; if(map[i][j][k]==‘S‘){ si=i;sj=j;sk=k; } } int ans=bfs(si,sj,sk); if(ans==0) printf("Trapped!\n"); else printf("Escaped in %d minute(s).\n",ans); } return 0; }
Time Limit: 1000 MS Memory Limit: 65536 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
Escaped in x minute(s).where x is replaced by the shortest time it takes to escape. If it is not possible to escape, print the line
Trapped!
3 4 5 S.... .###. .##.. ###.# ##### ##### ##.## ##... ##### ##### #.### ####E 1 3 3 S## #E# ### 0 0 0
Escaped in 11 minute(s). Trapped!
题意:三维空间 S起点 E终点 #不可以走 同样求最少步骤 所以依旧广搜
类似于二维哒~~~~~~~~
标签:des style blog http color java os io strong
原文地址:http://www.cnblogs.com/zhangying/p/3935838.html