zoukankan      html  css  js  c++  java
  • poj 2251 Dungeon Master(bfs)

    题目:http://poj.org/problem?id=2251

    View Code
     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #define pan(a,b,c) (a<=b&&b<=c)
     5 using namespace std;
     6 int dir[6][3]={{0,0,-1},{0,0,1},{-1,0,0},{1,0,0},{0,-1,0},{0,1,0}};
     7 int ex,ey,ez;
     8 char str[35][35][35];
     9 int map[35][35][35];
    10 struct node
    11 {
    12     int x,y,z;
    13     int num;
    14 }que[30010];
    15 int main()
    16 {
    17     int m,n,t;
    18     int i,j,k;
    19     int sx,sy,sz;
    20     while(scanf("%d%d%d%*c",&t,&m,&n)!=EOF)
    21     {
    22         if(t==0&&m==0&&n==0)
    23         break;
    24         for(i=1;i<=t;i++)
    25         {
    26             for(j=1;j<=m;j++)
    27             {
    28                 for(k=1;k<=n;k++)
    29                 {
    30                     cin>>str[i][j][k];
    31                     if(str[i][j][k]=='S')
    32                     {
    33                         sx=i;
    34                         sy=j;
    35                         sz=k;
    36                     }
    37                 }
    38             }
    39         }
    40         memset(map,0,sizeof(map));
    41         int head=0;
    42         int tail=1;
    43         que[0].x=sx;
    44         que[0].y=sy;
    45         que[0].z=sz;
    46         que[0].num=0;
    47         map[sx][sy][sz]=1;
    48         int xx,yy,zz;
    49         int flag=0;
    50         while(head<tail)
    51         {
    52 
    53             for(i=0;i<6;i++)
    54             {
    55                 xx=que[head].x+dir[i][0];
    56                 yy=que[head].y+dir[i][1];
    57                 zz=que[head].z+dir[i][2];
    58 
    59                 if(str[xx][yy][zz]=='E')
    60                 {
    61                     printf("Escaped in %d minute(s).\n",que[head].num+1);
    62                     flag=1;
    63                     break;
    64                 }
    65                 if(pan(1,xx,t)&&pan(1,yy,m)&&pan(1,zz,n)&&map[xx][yy][zz]==0&&str[xx][yy][zz]=='.')
    66                 {
    67                     que[tail].x=xx;
    68                     que[tail].y=yy;
    69                     que[tail].z=zz;
    70                     que[tail].num=que[head].num+1;
    71                     map[xx][yy][zz]=1;
    72                     tail++;
    73                 }
    74             }
    75             if(flag)
    76             break;
    77             head++;
    78         }
    79         if(!flag)
    80         {
    81             puts("Trapped!");
    82         }
    83     }
    84     return 0;
    85 }
  • 相关阅读:
    【转】umount 的时候报错:device is busy
    【转】linux shell 的tr命令
    给bash的提示符设置不同的颜色
    备份系统时候出现错误
    [转]Xen 的漫漫人生路
    linux/screen的指令
    扩大centos镜像的硬盘空间
    ASP.NET Web API学习资源
    svn make a tag
    query多选下拉框插件 jquerymultiselect
  • 原文地址:https://www.cnblogs.com/wanglin2011/p/2877764.html
Copyright © 2011-2022 走看看