Oil Deposits

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

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

#include <iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;

int n,m,sum;
][];
][],dir[][]= {,,,-,-,,-,-,,,,,,-,-,};//因为还有斜对角

void dfs(int x,int y)
{
    int tx,ty;
    ;i<;i++)
    {
        tx=x+dir[i][];
        ty=y+dir[i][];
         || tx>=n || ty< || ty>=m) continue;
        if(mapt[tx][ty]=='@')//将其周围@的符号全部改为*,开始搜索
        {
            mapt[tx][ty]='*';
            dfs(tx,ty);
        }
    }
}

int main()
{
    while(scanf("%d%d",&n,&m),n,m)
    {
        int i,j;
        memset(vis,,sizeof(vis));
        ; i<n; i++)
        {
            scanf("%s",mapt[i]);
        }
        sum=;
        ;i<n;i++)
        {
            ;j<m;j++)
            {
                if(mapt[i][j]=='@')
                {
                    mapt[i][j]='*';
                    dfs(i,j);
                    sum++;
                }
            }
        }
        printf("%d\n",sum);
    }
    ;
}

Oil Deposits的更多相关文章

  1. Oil Deposits(dfs)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  2. 2016HUAS暑假集训训练题 G - Oil Deposits

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  3. uva 572 oil deposits——yhx

    Oil Deposits  The GeoSurvComp geologic survey company is responsible for detecting underground oil d ...

  4. hdu 1241:Oil Deposits(DFS)

    Oil Deposits Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  5. hdu1241 Oil Deposits

    Oil Deposits                                                 Time Limit: 2000/1000 MS (Java/Others)  ...

  6. 杭电1241 Oil Deposits

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission ...

  7. HDU 1241 Oil Deposits --- 入门DFS

    HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...

  8. HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  9. UVa572 Oil Deposits DFS求连通块

      技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...

随机推荐

  1. java 选择排序

    import java.util.Scanner; public class SelectionSort { public static void sort(int[] a, int n){ if(n ...

  2. Y Combinator

    常见的例子 阶乘函数: fact = (a) -> if a > 0 then a * fact(a - 1) else 1 问题的提出 如上,在fact函数中调用了fact本身,无法使用 ...

  3. 1. Two Sum I & II & III

    1. Given an array of integers, return indices of the two numbers such that they add up to a specific ...

  4. Custom Web Servic In MOSS 2007

    Tools: Visual Studio 2008,Visual Studio 2008 Command Prompt, Sharepoint Server 2007 Generate .disco ...

  5. SQL Server数据库脚本备份与还原

    use[master]go /*完整--备份* backup 备份 * disk='E:\USERDB.bak' 磁盘,备份文件存放的路径* name='user' 备份显示的文件名称,可随意修改* ...

  6. GitHub的使用之新建与更新代码

    一.新建仓储:注册GitHub后你就会有0.3G的免费空间,不过只能创建公开项目,这也满足代码分享的目的,我最喜欢的倒是它的代码展示方式,可以直接浏览你的代码,代码是经过高亮.添加行号处理过的,十分漂 ...

  7. Observer pattern 观察者模式

    一.认识观察者模式 我们看看报纸和杂志的订阅是怎么回事: 1.报社的业务就是出版报纸. 2.向某家报社订阅报纸,只要他们有新的报纸出版,就会给你送来,只要你是他们的订户,你就会一直收到报纸. 3.当你 ...

  8. SQL指定字段指定顺序排序

    SELECT * FROM [ProjectInfo]ORDER BY (CASE DepartmentName WHEN 'AAA' THEN 1 WHEN 'BBB' THEN 2 WHEN 'C ...

  9. linux 系统负载高 如何检查

    1:load Average 1.1:什么是Load?什么是Load Average?    Load 就是对计算机干活多少的度量(WikiPedia:the system Load is a mea ...

  10. [转载]Three Trending Computer Vision Research Areas, 从CVPR看接下来几年的CV的发展趋势

    As I walked through the large poster-filled hall at CVPR 2013, I asked myself, “Quo vadis Computer V ...