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

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

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

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

      DFS解決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 <stdio.h>
      char M[101][101];
      int Used[101][101];
      int direction[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
      int i,j,p;
      int col,row;
      int iCount=0;

      void DFS(int x,int y)
      {
      int k;
      for(k=0;k<8;k++)
      {
      int tx= x+direction[k][0];
      int ty= y+direction[k][1];
      if(tx >= 0 && tx < row && ty >= 0 && ty < col && M[tx][ty] == 'W' && Used[tx][ty]==0)
      {
      Used[tx][ty]=1;
      DFS(tx,ty);
      }
      }
      }

      int main()
      {

      scanf("%d%d",&row,&col);
      for(i=0;i<row;i++)
      scanf("%s",M[i]);
      for(i=0;i<row;i++)
      {
      for(j=0;j<col;j++)
      {
      if(M[i][j]=='W' && Used[i][j] == 0)
      {
      Used[i][j]=1; //將其本身賦為已訪問過(注意:這一點容易被忽略)
      DFS(i,j);
      iCount++;
      }
      }
      }
      printf("%d\n",iCount);
      }


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

      導航

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

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

      主站蜘蛛池模板: 日本一区二区三区18岁| 久久无码中文字幕免费影院蜜桃| 99国产精品欧美一区二区三区| 亚洲精品日韩在线观看| 国产成人片无码视频在线观看| 中文字幕乱码中文乱码毛片| 日韩在线一区二区每天更新| 欧美日韩v| 日本精品aⅴ一区二区三区| 国产午夜福利小视频在线| 中文字幕在线观看一区二区| 99福利一区二区视频| 国产女人18毛片水真多1| 欧美交A欧美精品喷水| 永年县| 国产极品美女高潮无套| 高清国产av一区二区三区| 国产精品国产精品国产精品| 精品 日韩 国产 欧美 视频| 亚洲高清aⅴ日本欧美视频 | 福利一区二区在线观看| 日韩AV高清在线看片| 欧美成人精品手机在线| 人妻中文字幕不卡精品| 一本本月无码-| 国产不卡一区二区在线视频| 亚洲中文字幕人妻系列| 荥经县| 十八禁国产一区二区三区| 一卡2卡三卡4卡免费网站| 日本一区不卡高清更新二区| 亚洲AV无码不卡在线播放| 亚洲综合色在线视频WWW| 亚洲最大日韩精品一区| 亚洲国产免费图区在线视频| av在线中文字幕不卡电影网| 国产成人亚洲无码淙合青草| 无码一区二区三区中文字幕| 91精品国产午夜福利| 高清国产一区二区无遮挡| 欧美日韩国产图片区一区|