标签:turn names trap size ret iostream pac freopen cap
poj 2251
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;
char map[35][35][35];
int l,r,c;
bool book[35][35][35];
// 定义 东西南北和上下
struct dis{
int x,y,z;
int step;
dis(int x,int y,int z,int step):x(x),y(y),z(z),step(step){
}
};
int dx[6]={1,0,0,-1,0,0};
int dy[6]={0,1,-1,0,0,0};
int dz[6]={0,0,0,0,1,-1};
int bfs(int x,int y,int z){
queue<dis> st;
st.push(dis(x,y,z,0));
while(!st.empty()){
dis cur=st.front();
st.pop();
if(map[cur.x][cur.y][cur.z]==‘E‘){
return cur.step;
}
for(int i=0;i<6;i++){// 加入队列
int x=cur.x + dx[i];
int y=cur.y + dy[i];
int z=cur.z + dz[i];
if(x<l&&y<r&&z<c&&x>=0&&y>=0&&z>=0&&map[x][y][z]!=‘#‘&&!book[x][y][z]){
book[x][y][z]=1;
st.push(dis(x,y,z,cur.step+1));
}
}
}
return -1;
}
int main(){
freopen("p2251.txt","r",stdin);
while(scanf("%d%d%d",&l,&r,&c)&&l){
for(int j=0;j<l;j++){
for(int i=0;i<r;i++){
scanf("%s",map[j][i]);
}
scanf("\n");
}
memset(book,0,sizeof(book));
for(int i=0;i<l;i++)
for(int j=0;j<r;j++)
for(int k=0;k<c;k++)
if(map[i][j][k]==‘S‘){
int d=bfs(i,j,k);
if(d==-1){
cout<<"Trapped!\n";
}else{
printf("Escaped in %d minute(s).\n",d);
}
}
}
return 0;
}
标签:turn names trap size ret iostream pac freopen cap
原文地址:https://www.cnblogs.com/chichina/p/12659354.html