<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      書山有徑勤為路>>>>>>>>

      <<<<<<<<學海無涯苦作舟!

      BFS解決POJ 2251

      Description

      You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.

      Is an escape possible? If yes, how long will it take?

      Input

      The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
      L is the number of levels making up the dungeon.
      R and C are the number of rows and columns making up the plan of each level.
      Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.

      Output

      Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
      Escaped in x minute(s).

      where x is replaced by the shortest time it takes to escape.
      If it is not possible to escape, print the line
      Trapped!

      Sample Input

      3 4 5
      S....
      .###.
      .##..
      ###.#
      
      #####
      #####
      ##.##
      ##...
      
      #####
      #####
      #.###
      ####E
      
      1 3 3
      S##
      #E#
      ###
      
      0 0 0
      

      Sample Output

      Escaped in 11 minute(s).
      Trapped!
      
       
      此題目是三維的迷宮問題,要想解決本題,首先要有二維的BFS相關知識,
      有了這個之后,還是不行的,還要搞清楚行走的坐標的表示。
      一開始,我本以為要開一個三維的數組來表示走法,但是,用二維的才是正確的。
      如何正確,我將在代碼中做出詳細的說明。另外的一些注意事項,也會在代碼中
      做出詳細的解釋。
      View Code
      #include<iostream>
      #include<string.h>
      using namespace std;
      int level, row, col, i, j, k, sx, sy, sz, tx, ty, tz;
      char map[35][35][35];
      int used[35][35][35];
      int step[35][35][35];
      int direction[6][3] = {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};
      ///好了,現在來好好解釋一下direction[][]數組,也就是走法。一共有6種走法,上下左右前后。故要開direction[6][];
      ///為何要開direction[][3]呢?也就是這個3該如何解釋呢?學過幾何的人都知道x,y,z的空間坐標軸。這就是3的來歷。
      ///拿{0,0,1}來說,表示x=0, y=0, z=1,很明顯了,這種走法表示的是向上走了。其它的類似,不再說了。
      ///同樣的,direction[4][2]中的2,也是同樣的道理。只不過沒有了z坐標。
      struct point
      {
          int x,y,z;
      }queue[30000];
      int BFS(int sz, int sx, int sy)
      {
          used[sz][sx][sy] = 1;
          int head = 0, tail = 0;
          queue[head].z = sz;
          queue[head].x = sx;
          queue[head].y = sy;
          head++;
          while(tail<head)
          {
              point t1 = queue[tail];
              tail++;
              int m;
              for(m=0; m<6; m++)
              {
                  point t2;
                  t2.z = t1.z+direction[m][2];
                  t2.x = t1.x+direction[m][0];
                  t2.y = t1.y+direction[m][1];
                  if(t2.z>=0 && t2.z<level && t2.x>=0 && t2.x<row && t2.y>=0 && t2.y<col && used[t2.z][t2.x][t2.y]==0)
                  {
                      if(map[t2.z][t2.x][t2.y]=='.')
                      {
                          step[t2.z][t2.x][t2.y] = step[t1.z][t1.x][t1.y]+1;
                          used[t2.z][t2.x][t2.y] = 1;
                          queue[head] = t2;
                          head++;
                      }
                      else if(map[t2.z][t2.x][t2.y]=='E')
                          return (step[t1.z][t1.x][t1.y]+1);
                  }
              }
          }
          return -1;
      }
      int main()
      {
          while(cin>>level>>row>>col && (level+row+col))
          {
              memset(used, 0, sizeof(used));
              memset(step, 0, sizeof(step));
              for(i=0; i<level; i++)
                  for(j=0; j<row; j++)
                      for(k=0; k<col; k++)
                      {
                           cin>>map[i][j][k];
                          if(map[i][j][k]=='S')
                            ///一定要注意這里的map[i][j][k]中的三個參數i, j, k.
                           /// i 對應層數,也就是z軸
                     /// j 對應行數,也就是x軸
                     /// z 對應列數,也就是y軸
                     ///因此,在下面的運算中要一一對應起來的。否則將會出錯的。
                          {
                              sx = j; sy = k; sz = i; 
                          }
                      }
              int result = BFS(sz, sx, sy);
              if( result==-1 )
                  cout<<"Trapped!"<<endl;
              else
                  cout<<"Escaped in "<<result<<" minute(s)."<<endl;
          }
      }
      
      

       

       
      
      

      posted on 2011-09-23 22:34  More study needed.  閱讀(186)  評論(0)    收藏  舉報

      導航

      書山有徑勤為路>>>>>>>>

      <<<<<<<<學海無涯苦作舟!

      主站蜘蛛池模板: 一本本月无码-| 久久精品一区二区东京热| 毛片在线看免费| 泰宁县| 亚洲国产色婷婷久久99精品91| 国产高清自产拍AV在线| 东丰县| 国产精品黄色精品黄色大片 | 99久久久国产精品消防器材| 无套内射视频囯产| 97人妻天天爽夜夜爽二区| 日本japanese丰满白浆| 欧美国产精品啪啪| 久久精品不卡一区二区| 国产乱妇乱子视频在播放| 国产在线精品福利91香蕉| 国产精品自拍中文字幕| 亚洲无人区一区二区三区| 亚洲伊人久久综合影院| 中文字幕无线码免费人妻| 免费无码AV一区二区波多野结衣| 蜜臀一区二区三区精品免费| 狠狠躁夜夜躁人人爽天天5| 吉川爱美一区二区三区视频| 精品嫩模福利一区二区蜜臀| 四虎影视久久久免费| 青青狠狠噜天天噜日日噜| 成人午夜电影福利免费| 亚洲中文字幕在线二页| 97成人碰碰久久人人超级碰oo| 粉嫩蜜臀av一区二区绯色| 99久久99久久精品免费看蜜桃| 国产精品多p对白交换绿帽| 天天躁久久躁日日躁| 日韩大片看一区二区三区| 少妇无套内射中出视频| 国产女人喷潮视频免费| 成人中文在线| 好爽毛片一区二区三区四| 亚洲精品香蕉一区二区| 日韩av熟女人妻一区二|