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

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

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

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

      BFS解決POJ 2243

      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坐標。
      structpoint
      {
      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)
      {
      pointt1 = queue[tail];
      tail++;
      int m;
      for(m=0; m<6; m++)
      {
      pointt2;
      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:40  More study needed.  閱讀(213)  評論(0)    收藏  舉報

      導航

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

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

      主站蜘蛛池模板: 久久香蕉欧美精品| 粉嫩小泬无遮挡久久久久久| 中文字幕乱妇无码av在线 | 乱中年女人伦av三区| 乌拉特中旗| 国产综合精品一区二区三区| 国产av一区二区久久蜜臀| 日韩黄色av一区二区三区| 日本中文字幕乱码免费| 一区二区三区四区亚洲综合| 久久99久久99精品免视看国产成人| 国产激情视频在线观看首页| 高清国产美女一级a毛片在线| 高邮市| 日日爽日日操| 国产亚洲精久久久久久久91| 小嫩批日出水无码视频免费| 久久精品久久黄色片看看| 国产亚洲精品自在久久vr| 男女一级国产片免费视频| 亚洲尤码不卡av麻豆| 精品久久久久久中文字幕| 亚洲v国产v天堂a无码二区| 亚洲成在人线在线播放无码| 扶沟县| 久久精品蜜芽亚洲国产AV| 日韩人妻系列无码专区| 国产女人18毛片水真多1| 欧美一区二区三区在线观看| 啊轻点灬大JI巴太粗太长了在线| 四虎www永久在线精品| 精品国产熟女一区二区三区| 欧美性群另类交| 午夜毛片不卡免费观看视频| 蜜臀av性久久久久蜜臀aⅴ麻豆| 双腿张开被5个男人调教电影| 少妇办公室好紧好爽再浪一点| 国产精成人品| 亚洲天堂成人网在线观看| 福利一区二区在线播放| 人人妻人人做人人爽夜欢视频 |