标签:present cstring short ring generate cap str i++ front
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 32684 | Accepted: 12529 |
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!
Source
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; struct node{ int x,y,z; int step; }; int l,r,c; char maze[40][40][40]; int vis[40][40][40]; node start; node endd; int directx[7]={0,0,0,0,1,-1}; int directy[7]={-1,1,0,0,0,0}; int directz[7]={0,0,-1,1,0,0}; int findd(){ queue<node> que; memset(vis,0,sizeof(vis)); start.step=0; que.push(start); while(!que.empty()){ node now=que.front(); que.pop(); for(int i=0;i<6;i++){ node next=now; next.x+=directx[i]; next.y+=directy[i]; next.z+=directz[i]; int xx=next.x; int yy=next.y; int zz=next.z; if(maze[xx][yy][zz]==‘#‘||vis[xx][yy][zz]||!(xx>=0&&xx<l&&yy>=0&&yy<r&&yy>=0&&zz>=0&&zz<c)){ continue; } if(maze[xx][yy][zz]==‘E‘){ next.step+=1; return next.step; } if(maze[xx][yy][zz]==‘.‘){ next.step+=1; vis[xx][yy][zz]=1; que.push(next); } } } return 0; } int main() { while(scanf("%d %d %d",&l,&r,&c)&&(l+r+c!=0)){ getchar(); for(int i=0;i<l;i++,getchar()){ for(int j=0;j<r;j++,getchar()){ for(int k=0;k<c;k++){ scanf("%c",&maze[i][j][k]); if(maze[i][j][k]==‘S‘){ start.x=i; start.y=j; start.z=k; } } } } int ans=findd(); if(ans){ printf("Escaped in %d minute(s).\n",ans); }else{ printf("Trapped!\n"); } } return 0; }
标签:present cstring short ring generate cap str i++ front
原文地址:http://www.cnblogs.com/TWS-YIFEI/p/6696677.html