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

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

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

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

      BFS最短路徑的記錄

      在網上看到了一個記錄BFS最短路徑的方法,

      個人覺得相當的牛B,所以就將它記錄下來了。

      題目:http://acm.hdu.edu.cn/showproblem.php?pid=1026

      這個題目比較簡單,就不說題意了。

       

      直接上代碼:

      View Code
      #include "iostream"
      #include "cstring"
      #include "cstdio"
      #include "algorithm"
      #include "queue"
      using namespace std;
      #define MAX 1000000
      typedef struct Path{
          int time;
          int x, y;
          int ttime;
      }Path;
      typedef struct Point{
          int x, y;
      }Point;
      int d[4][2]={{-1, 0}, {1, 0},{0, -1},{0, 1}};
      Point p1, p2;
      int Row, Col;
      Path Map[105][105];//這個你想到用過嗎,沒有吧,就只是這個已經是很大的亮點了,也可以說是整個題目的最大亮點了
      void BFS(){
          queue<Point> q;
          Map[0][0].time = 0;
          p1.x = Row-1;
          p1.y = Col-1;
          Map[Row-1][Col-1].ttime = Map[Row-1][Col-1].time;
          q.push(p1);
          while(!q.empty()){
              p1 = q.front();
              q.pop();
              if(p1.x==0 && p1.y==0) continue;
              for(int k=0; k<4; k++){
                  p2.x = p1.x+d[k][0];
                  p2.y = p1.y+d[k][1];
                  if(p2.x<0 || p2.x>Row-1 || p2.y<0 || p2.y>Col-1 || Map[p2.x][p2.y].time==-1)
                      continue;
                  if(Map[p1.x][p1.y].ttime+Map[p2.x][p2.y].time<Map[p2.x][p2.y].ttime){
                      Map[p2.x][p2.y].ttime = Map[p1.x][p1.y].ttime+Map[p2.x][p2.y].time;
                      Map[p2.x][p2.y].x = p1.x;
                      Map[p2.x][p2.y].y = p1.y;
                      q.push(p2);
                  }
              }
          }
      }
      int main(){
          char ch;
          while(cin>>Row>>Col){
              getchar();
              for(int i=0; i<Row; i++){
                  for(int j=0; j<Col; j++){
                      cin>>ch;
                      Map[i][j].ttime = MAX;
                      if(ch=='.') Map[i][j].time = 1;
                      else if(ch=='X') Map[i][j].time = -1;
                      else Map[i][j].time = ch-'0'+1;
                  }
                  getchar();
              }
              int i, j, k, h;
              BFS();
              if(Map[0][0].ttime==MAX) printf("God please help our poor hero.\n");
              else{
                  i=0;j=k=0;
                  printf("It takes %d seconds to reach the target position, let me show you the way.\n",Map[0][0].ttime);
                  while(i<Map[0][0].ttime){
                      if(Map[j][k].time>1){
                          while(--Map[j][k].time){
                              i++;
                              printf("%ds:FIGHT AT (%d,%d)\n",i,j,k);
      
                          }
                      }else{
                          i++;
                          printf("%ds:(%d,%d)->(%d,%d)\n",i,j,k,Map[j][k].x,Map[j][k].y);
                          h=Map[j][k].x;
                          k=Map[j][k].y;
                          j=h;
                      }
                  }
              }
              printf("FINISH\n");
          }
      }

      posted on 2012-04-28 16:51  More study needed.  閱讀(719)  評論(0)    收藏  舉報

      導航

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

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

      主站蜘蛛池模板: 东方四虎av在线观看| 成人无码午夜在线观看| 亚洲国产欧美在线看片一国产 | 99久久亚洲综合精品网| 国产精品久久国产三级国不卡顿 | 国产偷国产偷亚洲高清日韩| 亚洲人成网站18禁止| 日韩精品一区二区亚洲av| 成人国产精品一区二区不卡 | 亚洲综合精品第一页| 一区二区不卡国产精品| 人妻丝袜无码专区视频网站| 亚洲国产午夜精品理论片| 国产一卡2卡三卡4卡免费网站| 国产熟睡乱子伦视频在线播放| 精品国产丝袜自在线拍国语| 国产在线国偷精品产拍| 宅男久久精品国产亚洲av麻豆| 干老熟女干老穴干老女人| 特级精品毛片免费观看| 免费人成网站免费看视频| 青青狠狠噜天天噜日日噜| 激情综合色综合啪啪开心| 性色a∨精品高清在线观看| 性一交一乱一伦一| 国产99久久亚洲综合精品西瓜tv| 青青青爽在线视频观看| julia无码中文字幕一区| 欧美高清精品一区二区| 国产精品午夜福利片国产| 狠狠色综合久久丁香婷婷| 成在线人永久免费视频播放 | 亚洲色婷婷一区二区三区| 欧美成人精品一级在线观看| 久久久av男人的天堂| 夜夜爽妓女8888888视频 | 精品中文人妻在线不卡| WWW丫丫国产成人精品| 欧美疯狂三p群体交乱视频| 人妻日韩人妻中文字幕| 老司机精品成人无码av|