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. maven添加本地jar包

    今天遇到一个mavan仓库中没有的jar包, 故只能添加本地jar包, 花了不少时间找资料,终于OK.故在此记录. 1. 第一次,在网上看到说可以用<systemPath> 解决, 如下: ...

  2. Linux 常用命令集合

    1. 常用命令 ls  显示当前目录下的文件和文件夹: -ltr 按时间顺序显示文件和文件夹的详细信息,不带参数的时候 只显示文件夹和文件. vi  打开文件的内容 tar -cvf file.tar ...

  3. Centos 6.5 把自带python 2.6.6, 升级到 2.7

    http://blog.csdn.net/jcjc918/article/details/11022345

  4. 《Linux内核设计与实现》课本第五章学习笔记——20135203齐岳

    <Linux内核设计与实现>课本第五章学习笔记 By20135203齐岳 与内核通信 用户空间进程和硬件设备之间通过系统调用来交互,其主要作用有三个. 为用户空间提供了硬件的抽象接口. 保 ...

  5. uiscrollView UINavigation和uitabbar添加约束的问题

    首先是层次问题, 我的storyboard中 底层是一个View(viewcontroller自带)上面添加了一个UIScrollview(添加约束, 上下左右全为0), 在UIScrollview上 ...

  6. js 判断IE浏览器,包含IE6/7/8/9

    //判断IE6-9的版本,num可取值为6/7/8/9//若不给参数num,仅判断浏览器是否为IE,不判断版本 var isIE = function (num) { if(arguments.len ...

  7. Xcode5 + phoneGap2.9搭建ios开发环境-配置-测试-归档上传/phoneG...

    前言: 小弟是做JAVA/Android的第一次搞这个ios,公司有mobile项目是使用phoneGap开发的,需要开发ios版本.什么都不会只能一点一点琢磨了……大神越过…… 原文链接:http: ...

  8. swift 计算label的行数方法

    这主要针对是 cell上label自适应高度, let lineSpaceKey = "lineSpaceKey" extension UILabel{ var lineSpace ...

  9. Myeclipse安装SVN插件(转)

    方法一:在线安装 1.打开HELP->MyEclipse Configuration Center.切换到SoftWare标签页. 2.点击Add Site 打开对话框,在对话框Name输入Sv ...

  10. Xcode真机调试报错(证书的签发者无效)

    Xcode真机调试时报错: dyld: Library not loaded: @rpath/libswiftAVFoundation.dylib Referenced from: /var/mobi ...