• Oil Deposits


    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 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

    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<iostream>
     2 using namespace std;
     3 int n,m;
     4 char grid[105][105];//存储网格;
     5 int dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{0,-1},{1,1},{1,0},{1,-1}};
     6 void DFS(int x,int y)//从(x,y)位置进行DFS
     7 {
     8     int i,xx,yy;
     9     grid[x][y]='*';//进过后设置成*保证不会在经过了
    10     for(i=0;i<8;i++)
    11     {
    12         xx=x+dir[i][0];
    13         yy=y+dir[i][1];
    14         if(xx>=n||yy>=m||xx<0||yy<0)//判断
    15         continue;
    16         if(grid[xx][yy]!='*')
    17         DFS(xx,yy);
    18     }
    19 }
    20 int main()
    21 {
    22     int i,j;
    23     int count;//统计数目
    24     while(cin>>n>>m,n)
    25     {
    26         cin.get();
    27         for(i=0;i<n;i++)
    28         {
    29             for(j=0;j<m;j++)
    30             cin>>grid[i][j];
    31             cin.get();
    32         }
    33         count=0;
    34         for(i=0;i<n;i++)
    35         {
    36             for(j=0;j<m;j++)
    37             {
    38                 if(grid[i][j]=='@')
    39                 {
    40                     DFS(i,j);//从(i,j)位置进行DFS;
    41                     count++;
    42                 }
    43             }
    44         }
    45         cout<<count<<endl;
    46     }
    47     return 0;
    48 } 
    View Code
  • 相关阅读:
    HTML a标签的href 属性 tel 点击可以直接拨打电话 ( 移动端 )
    【集群实战】NFS网络文件共享服务3-相关知识补充(showmount,exports,rpc)
    【集群实战】NFS网络文件共享服务2-mount挂载(参数,优化)
    Linux发送邮件命令mail,mutt
    【集群实战】NFS服务常见故障排查和解决方法
    【集群实战】NFS网络文件共享服务
    【集群实战】Rsync试题-异机数据备份解决方案
    【集群实战】Rsync常见错误总结
    【集群实战】Rsync数据同步工具
    【shell】Shell变量基础及深入
  • 原文地址:https://www.cnblogs.com/demodemo/p/4690647.html
Copyright © 2020-2023  润新知