zoukankan      html  css  js  c++  java
  • HDU_1241——石油探索DFS

    Problem Description
    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid. 
     
    Input
    The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.
     
    Output
    For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
     
    Sample Input
    1 1 * 3 5 *@*@* **@** *@*@* 1 8 @@****@* 5 5 ****@ *@@*@ *@**@ @@@*@ @@**@ 0 0
     
    Sample Output
    0 1 2 2
     1 #include <stdio.h>
     2 char map[100][100];
     3 int num,m,n;
     4 void Dfs(int i,int j)
     5 {
     6    if(i>=0&&i<=m&&j>=0&&j<=n&&map[i][j]=='@')
     7       {
     8          map[i][j]='#';//记录走过之后不再复原路劲,表示这条路已经走过了 
     9          Dfs(i+1,j);
    10          Dfs(i-1,j);
    11          Dfs(i,j+1);
    12          Dfs(i,j-1);
    13          Dfs(i+1,j+1);
    14          Dfs(i+1,j-1);
    15          Dfs(i-1,j-1);
    16          Dfs(i-1,j+1);
    17       }
    18 }
    19 int main()
    20 {
    21    while(scanf("%d%d",&m,&n)!=EOF && m!=0)
    22       {
    23          num=0;
    24          for(int i=0;i<m;i++)
    25             scanf("%s",map[i]);
    26          for(int i=0;i<m;i++)
    27             for(int j=0;j<n;j++)
    28                if(map[i][j]=='@')
    29                   {
    30                      Dfs(i,j);
    31                      num++;   
    32                   }
    33          printf("%d
    ",num);
    34       }  
    35 }
    ——现在的努力是为了小时候吹过的牛B!!
  • 相关阅读:
    JQuery上传插件Uploadify使用详解
    c#.net 生成清晰缩略图的解决方案
    PS图片上传图片 同时生成微缩图
    无限极”分类数据表设计的简单再总结
    Web开发者必备的12款超赞jQuery插件
    mssql中对于bit类型字段的更新
    SQL Server存储多语言数据的几种方法
    正则表达式测试工具RegexTester
    .Net 2.0 正则表达式里的$在Multiline模式下的精确含意
    终于搞定了终端服务客户端三个月重装一次的问题
  • 原文地址:https://www.cnblogs.com/pingge/p/3185617.html
Copyright © 2011-2022 走看看