zoukankan      html  css  js  c++  java
  • hdu 1241 Oil Deposits

    Oil Deposits

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


    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
     
    Source
     
    PS:第一次提交就AC了,算是小欣慰吧
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<cstdlib>
     6 using namespace std;
     7 int vis[103][103];
     8 char map[103][103];
     9 int n,m;
    10 int dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
    11             //方向左上,上,右上,左,右,左下,下,右下
    12 
    13 
    14 void dfs(int x,int y)
    15 {
    16     int ss,vv,i;
    17     for(i=0;i<8;i++)
    18     {
    19         ss=x+dir[i][0];
    20         vv=y+dir[i][1];
    21         if(ss>=0&&ss<n && vv>=0&&vv<m &&map[ss][vv]=='@' && !vis[ss][vv])
    22         {
    23             vis[ss][vv]=1;
    24             dfs(ss,vv);
    25         }
    26     }
    27     return ;
    28 }
    29 
    30 int main()
    31 {
    32     //freopen("in.txt","r",stdin);
    33     while(~scanf("%d%d",&n,&m))
    34     {
    35         memset(vis,0,sizeof(vis));
    36         int i,j;
    37         int sum=0;
    38         if(!n&&!m)
    39         break;
    40         for(i=0;i<n;i++)
    41         scanf("%s",map[i]);
    42         for(i=0;i<n;i++)
    43         {
    44             for(j=0;j<m;j++)
    45             {
    46                 if(!vis[i][j] && map[i][j]!='*')
    47                 {
    48                     dfs(i,j);
    49                     sum++;
    50                 }
    51             }
    52         }
    53         printf("%d
    ",sum);
    54     }
    55     return 0;
    56 }
    View Code
  • 相关阅读:
    简体中文和繁体中文的转换
    EasyPoi 快速Office 开发
    玩转SpringBoot之定时任务详解
    Spring Boot中使用Swagger2构建强大的RESTful API文档
    一篇文章带你搞懂 SpringBoot与Swagger整合
    JAVA团队开发手册
    CentOS(6、7)修改主机名(hostname)
    SpringBoot多环境部署,在启动时动态设置相应的配置文件
    MyBatis逆向工程代码的生成以及使用详解(持续更新)
    MySQL写入插入数据优化配置
  • 原文地址:https://www.cnblogs.com/xuesen1995/p/4125968.html
Copyright © 2011-2022 走看看