![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//**************************************
Problem: HEU 1042 Dungeon Master
Time: 0.0090 s
Memory: 916 k
Accepted Time: 2009-05-06 19:19:33
Tips: 注意计算层数的方法
**************************************/
#include <stdio.h>
#include <string.h>
char a[31][31][31];
bool b[31][31][31];
int queue[100000][3];
int l,c,r;
bool fun(int a0,int a1,int a2)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
if(a0<0||a0>=l)return 0;
if(a1<0||a1>=c)return 0;
if(a2<0||a2>=r)return 0;
if(b[a0][a1][a2]||a[a0][a1][a2]=='#')return 0;
return 1;
}
int main()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int i,j,k;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
int step[6][3]=
{0,0,1,0,0,-1,0,1,0,0,-1,0,1,0,0,-1,0,0};
while(1)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
scanf("%d%d%d",&l,&c,&r);
if(l==0&&c==0&&r==0)break;
int end[3],flag=0;
memset(b,0,sizeof(b));
for(i=0;i<l;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(j=0;j<c;j++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
scanf("%s",a[i][j]);
if(flag==0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(k=0;k<r;k++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(a[i][j][k]=='S')
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
queue[0][0]=i;
queue[0][1]=j;
queue[0][2]=k;
b[i][j][k]=1;
flag=1;
}
}
}
}
}
int front=0,rear=1,floor=0,temp=0;
while(front<rear)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(i=0;i<6;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int a0=queue[front][0]+step[i][0];
int a1=queue[front][1]+step[i][1];
int a2=queue[front][2]+step[i][2];
if(fun(a0,a1,a2))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(a[a0][a1][a2]=='E')goto haha;
queue[rear][0]=a0;
queue[rear][1]=a1;
queue[rear][2]=a2;
b[a0][a1][a2]=1;
rear++;
}
}
if(front==temp)//计算层数
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
floor++;
temp=rear-1;
}
front++;
}
haha:
if(front<rear)printf("Escaped in %d minute(s).\n",floor+1);
else printf("Trapped!\n");
}
return 0;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
posted @
2009-05-06 19:27
主函数
阅读(
144)
评论()
编辑
收藏
举报