标签:des style blog http color os strong io
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16468 | Accepted: 6395 |
Description
Input
Output
Escaped in x minute(s).
Trapped!
Sample Input
3 4 5 S.... .###. .##.. ###.# ##### ##### ##.## ##... ##### ##### #.### ####E 1 3 3 S## #E# ### 0 0 0
Sample Output
Escaped in 11 minute(s). Trapped!
1 /*====================================================================== 2 * Author : kevin 3 * Filename : DungeonMaster.cpp 4 * Creat time : 2014-08-02 09:40 5 * Description : 6 ========================================================================*/ 7 #include <iostream> 8 #include <cstdio> 9 #include <cstring> 10 #include <queue> 11 using namespace std; 12 struct Node 13 { 14 int x,y,z; 15 char c; 16 }; 17 int cnt[31][31][31],vis[31][31][31],xx,yy,zz; 18 int cc[6][3]={{-1,0,0},{1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}}; 19 char s[31][31][31]; 20 void BFS(int a,int b,int c) 21 { 22 queue<Node>que; 23 Node node,ch,sh; 24 int q,w,e; 25 node.c=s[a][b][c]; 26 node.x=a;node.y=b;node.z=c; 27 que.push(node); 28 while(!que.empty()){ 29 ch=que.front(); 30 if(ch.c==‘E‘) 31 break; 32 que.pop(); 33 for(int i=0;i<6;i++){ 34 q=ch.x+cc[i][0]; 35 w=ch.y+cc[i][1]; 36 e=ch.z+cc[i][2]; 37 if(!vis[q][w][e] && q>=0&&q<xx && w>=0&&w<yy && 38 e>=0&&e<zz){ 39 cnt[q][w][e]=cnt[ch.x][ch.y][ch.z]+1; 40 sh.c=s[q][w][e]; 41 sh.x=q;sh.y=w;sh.z=e; 42 que.push(sh); 43 vis[q][w][e]=1; 44 } 45 } 46 } 47 } 48 int main() 49 { 50 int as,bs,cs,ae,be,ce; 51 while(scanf("%d%d%d",&xx,&yy,&zz)!=EOF && xx+yy+zz){ 52 memset(s,0,sizeof(s)); 53 memset(vis,0,sizeof(vis)); 54 memset(cnt,0,sizeof(cnt)); 55 for(int i=0;i<xx;i++){ 56 for(int j=0;j<yy;j++){ 57 getchar(); 58 for(int k=0;k<zz;k++){ 59 scanf("%c",&s[i][j][k]); 60 if(s[i][j][k]==‘S‘){ 61 as=i;bs=j;cs=k; 62 } 63 if(s[i][j][k]==‘E‘){ 64 ae=i;be=j;ce=k; 65 } 66 if(s[i][j][k]==‘#‘){ 67 vis[i][j][k]=1; 68 } 69 } 70 } 71 getchar(); 72 } 73 vis[as][bs][cs]=1; 74 BFS(as,bs,cs); 75 if(cnt[ae][be][ce]==0){ 76 printf("Trapped!\n"); 77 } 78 else printf("Escaped in %d minute(s).\n",cnt[ae][be][ce]); 79 } 80 return 0; 81 }
poj 2251 -- Dungeon Master,布布扣,bubuko.com
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/ubuntu-kevin/p/3886542.html