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. 定位 position: absolute & relative

    [position:absolute] 意思是绝对定位,他默认参照浏览器的左上角,配合TOP.RIGHT.BOTTOM.LEFT(下面简称TRBL)进行定位,有以下属性: 1)如果没有TRBL,以父级 ...

  2. memcached 的简介、安装、命令

    一.memcached 概述 Memcache(内存,缓存) : 是一个高性能的分布式的内存对象缓存系统.通过在内存里维护一个巨大的hash表.(key=value) Hash表 key(键) val ...

  3. 深入浅出Mybatis系列(六)---objectFactory、plugins、mappers简介与配置

    上篇文章<深入浅出Mybatis系列(五)---TypeHandler简介及配置(mybatis源码篇)>简单看了一下TypeHandler, 本次将结束对于mybatis的配置文件的学习 ...

  4. MySQL ERROR 1005: Can't create table (errno: 150)的错误解决办法

    在mysql 中建立引用约束的时候会出现MySQL ERROR 1005: Can't create table (errno: 150)的错误信息结果是不能建立 引用约束. 出现问题的大致情况 1. ...

  5. 一个网络传输框架——zeroMQ 调研笔记

    一.它是什么 zeroMQ,一个处理消息传输的库,重点在传输上,看起来它像是在socket上面封装了一层,让我们可以很容易的利用它来做N对M的数据传输,在分布式系统中很方便,在接收端它有round-r ...

  6. SpringAOP实现(原理)

    AOP原理: AOP分为:JDK动态代理和CGLIB代理 静态代理:由程序员创建或特定工具自动生成源代码,再对其编译.在程序运行前,代理类的.class文件就已经存在了.              注 ...

  7. 个人纪录(初)----Ueditor文本编辑器的引用

    源码下载地址:http://ueditor.baidu.com/website/ 打开源码参考.html 把ueditor引入自己的web项目下. 在需要引入文本的地方写个div,设置样式等. 并且在 ...

  8. nginx 安装与配置

    centos7环境下nginx的安装  版本 0.85 tar zxvf nginx.tar.gz cd nginx ./configure // ./configure --help 查看编译选项 ...

  9. 计算机网络(8)-----TCP报文段的首部格式

    TCP报文段的首部格式 概述 TCP报文段首部的前20个字节是固定的,因此TCP首部的最小长度是20字节. 源端口和目标端口 各占2个字节,分别写入源端口号和目的端口号. 序列号 占4个字节,表示本报 ...

  10. hongxin

    邀请链接 :http://honx.in/_VbiG2CZDjwIE8l1t