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

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

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

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

      BFS解決POJ 2386

      Description

      Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John would like to figure out how many ponds have formed in his field. A pond is a connected set of squares with water in them, where a square is considered adjacent to all eight of its neighbors.

      Given a diagram of Farmer John's field, determine how many ponds he has.

      Input

      * Line 1: Two space-separated integers: N and M

      * Lines 2..N+1: M characters per line representing one row of Farmer John's field. Each character is either 'W' or '.'. The characters do not have spaces between them.

      Output

      * Line 1: The number of ponds in Farmer John's field.

      Sample Input

      10 12
      W........WW.
      .WWW.....WWW
      ....WW...WW.
      .........WW.
      .........W..
      ..W......W..
      .W.W.....WW.
      W.W.W.....W.
      .W.W......W.
      ..W.......W.

      Sample Output

      3
      
      
      View Code
      #include "iostream"
      #include "string"
      using namespace std;
      int used[105][105];
      char map[105][105];
      int direction[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
      struct point
      {
          int x;
          int y;
      }queue[10005];
      int si, sj, iColumn, iRow, count;
      void bfs()
      {
          int head = 0, tail = 0;
          used[si][sj] = 1;
          queue[head].x = si;  //搜索的初始x坐標
          queue[head].y = sj;  //搜索的初始y坐標
          head++;
          while(tail<head)
          {
              point temp1 = queue[tail];
              tail++;
              int k, m;
              for(k=0; k<8; k++)
              {
                  point temp2;
                  temp2.x = temp1.x+direction[k][0];  
                  temp2.y = temp1.y+direction[k][1]; 
                  if(temp2.x>=0 && temp2.x<iRow && temp2.y>=0 && temp2.y<iColumn && !used[temp2.x][temp2.y] && map[temp2.x][temp2.y]=='W')
                  {
                      used[temp2.x][temp2.y] = 1;
                      queue[head] = temp2;
                      head++;
                  }
              }
          }
      }
      int main()
      {
          int i, j;
          while(cin>>iRow>>iColumn)
          {
              memset(used, 0, sizeof(used));
              count=0;
              for(i=0; i<iRow; i++)
                  for(j=0; j<iColumn; j++)
                      cin>>map[i][j];
                   for(i=0; i<iRow; i++)
                  for(j=0; j<iColumn; j++)
                  {
                      if(map[i][j]=='W' && used[i][j]==0)  //一旦遇到了W,并且沒有被訪問過就bfs(),count++;
                      {
                          si = i;
                          sj = j;
                          bfs();
                          count++;
                      }
                  }
              cout<<count<<endl;
          }
          return 0;
      }

       

      
      
       

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

      導航

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

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

      主站蜘蛛池模板: 国产精品久久久久影院色| 亚洲情A成黄在线观看动漫尤物 | 少妇人妻精品无码专区视频| 国语自产精品视频在线看| 1024你懂的国产精品| 华人在线亚洲欧美精品| 欧美一区二区| 精品国产一区二区三区国产区| 久久天天躁夜夜躁狠狠综合| 六十路老熟妇乱子伦视频| 亚洲一区二区精品动漫| 亚洲综合久久精品国产高清| 国产成人无码免费视频在线| 中文日产乱幕九区无线码| 日韩高清免费一码二码三码| 亚洲综合精品第一页| 欧美性猛交xxxx免费看| 亚洲人成亚洲人成在线观看| 成人一区二区三区在线午夜| 色欲AV无码一区二区人妻| 夜爽8888视频在线观看| 国产偷国产偷亚洲综合av| 亚洲老妇女一区二区三区| 偷拍精品一区二区三区| 日韩高清亚洲日韩精品一区二区| 她也色tayese在线视频| 国产精品一区二区久久精品无码 | 亚洲欧美精品一中文字幕| 亚洲精品一区二区毛豆| 亚洲欧美日韩精品成人| 亚洲国产成人综合精品| 欧美和黑人xxxx猛交视频| 久久99国产乱子伦精品免费| 超碰成人精品一区二区三| 4hu44四虎www在线影院麻豆| 性欧美老妇另类xxxx| 国产成人亚洲一区二区三区| 免费人成网站免费看视频| 逊克县| 国产精品无遮挡猛进猛出| 国产无套护士在线观看|