zoukankan      html  css  js  c++  java
  • uva 572 oil deposits——yhx

    Oil Deposits 

    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 le m le 100$ and $1 le n le 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.

     1 #include<cstdio>
     2 #include<cstring>
     3 int xx[8]={-1,-1,-1,0,0,1,1,1},yy[8]={-1,0,1,-1,1,-1,0,1},m,n;
     4 bool map[110][110];
     5 void dfs(int x,int y)
     6 {
     7     int i,j,k,p,q;
     8     for (i=0;i<=7;i++)
     9     {
    10       p=x+xx[i];
    11       q=y+yy[i];
    12       if (p>=1&&p<=m&&q>=1&&q<=n&&map[p][q])
    13       {
    14           map[p][q]=0;
    15           dfs(p,q);
    16       }
    17     }
    18 }
    19 int main()
    20 {
    21     int i,j,k,p,q,ans;
    22     char c,s[150];
    23     while (scanf("%d%d",&m,&n)&&m&&n)
    24     {
    25         memset(map,0,sizeof(map));
    26         gets(s);
    27         for (i=1;i<=m;i++)
    28         {
    29             gets(s+1);
    30             for (j=1;j<=n;j++)
    31               if (s[j]=='@')
    32                 map[i][j]=1;
    33         }
    34         ans=0;
    35         for (i=1;i<=m;i++)
    36           for (j=1;j<=n;j++)
    37             if (map[i][j]) 
    38             {
    39                 map[i][j]=0;
    40                 dfs(i,j);
    41                 ans++;
    42             }
    43         printf("%d
    ",ans);
    44     }
    45 } 

    每找到一个点,就将他DFS,标记掉所有周围的点。

  • 相关阅读:
    架构 框架 设计模式 --备用
    机器视觉项目开发之---织物疵点检测机器视觉系统 软件测试平台
    多媒体开发之--- live555 vs2010/vs2013下编译,使用,测试
    多媒体开发之--- h264 图像、帧、片、NALU
    多媒体开发之---H264—MP4格式及在MP4文件中提取H264的SPS、PPS及码流
    多媒体开发之---h264格式slice_header
    图像处理之基础---傅立叶c实现
    图像处理之基础---小波提取特征
    图像处理之基础---图像的特征简介
    嵌入式开发之工具---log file
  • 原文地址:https://www.cnblogs.com/SBSOI/p/5575045.html
Copyright © 2011-2022 走看看