HEU 1042 Dungeon Master

/**************************************
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)
{
    
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()
{
    
int i,j,k;
    
int step[6][3]={0,0,1,0,0,-1,0,1,0,0,-1,0,1,0,0,-1,0,0};
    
while(1)
    
{
        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++)
        
{
            
for(j=0;j<c;j++)
            
{
                scanf(
"%s",a[i][j]);
                
if(flag==0)
                
{
                    
for(k=0;k<r;k++)
                    
{
                        
if(a[i][j][k]=='S')
                        
{
                            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)
        
{
            
for(i=0;i<6;i++)
            
{
                
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))
                
{
                    
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)//计算层数  
            {
                floor
++;
                temp
=rear-1;
            }

            front
++;
        }

        haha:
        
if(front<rear)printf("Escaped in %d minute(s).\n",floor+1);
        
else printf("Trapped!\n");
    }

    
return 0;
}

posted @ 2009-05-06 19:27  主函数  阅读(144)  评论(0编辑  收藏  举报