zoukankan      html  css  js  c++  java
  • hdu1241 Oil Deposits

                                                     Oil Deposits

                                                    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
                                                                            Total Submission(s): 15084    Accepted Submission(s): 8660


    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
     
    DFS类型题
     1 #include<iostream>
     2 #include<cstdio>
     3 #define N 110
     4 using namespace std;
     5 
     6 int m,n;
     7 
     8 int dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
     9 
    10 char maps[N][N];
    11 
    12 int nx,ny;
    13 
    14 void dfs(int x,int y)
    15 {
    16 
    17     if(x<0||x>=m||y<0||y>=n)//判断当前所在位置是否合法;
    18         return ;
    19     if(maps[x][y]=='*')//递归结束条件;
    20         return ;
    21     else
    22     {
    23         maps[x][y]='*';
    24         for(int i=0;i<8;i++)//搜索相邻的8个方向;
    25         {
    26             nx=x+dir[i][0];
    27             ny=y+dir[i][1];
    28             dfs(nx,ny);//进行深搜;
    29         }
    30 
    31     }
    32 }
    33 
    34 int main()
    35 {
    36     int i,j,ans;
    37 
    38     while(cin>>m>>n,m+n)
    39     {
    40         ans=0;
    41 
    42         for(i=0; i<m; i++)
    43             scanf("%s",maps[i]);
    44         for(i=0; i<m; i++)
    45         {
    46             for(j=0; j<n; j++)
    47             {
    48                 if(maps[i][j]=='@')
    49                 {
    50                     dfs(i,j);
    51                     ans++;
    52                 }
    53             }
    54         }
    55         printf("%d
    ",ans);
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    移动端页面制作字号大小设定问题,设计稿文字字号规范,解决移动端大小屏适配问题
    iPhone分辨率详细对比
    Flex 布局教程:语法篇
    带有可点击区域的图像映射(area)
    Stellar.js视差插件
    json中含有换行符' ',' '的处理
    windows下基于(QPC)实现的微秒级延时
    实现memcpy()函数及过程总结
    Welcome to MarkdownPad 2
    Cmake+Opencv+mingw+QT环境配置
  • 原文地址:https://www.cnblogs.com/zhengguiping--9876/p/4344198.html
Copyright © 2011-2022 走看看