Oil Deposits

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

————————————————————————————————————————————————————

DFS求连通块入门题,直接把地图跑一边,找到符合点计数一下,dfs遍历所有的连通块变成普通的。


#include<iostream>
#include<cmath>
using namespace std;
char map[105][105];
int m, n, t;
int dir[8][2] = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, {1,1} }; void dfs(int si, int sj)
{
if (si <= 0 || sj <= 0 || si > m || sj > n)
return;
for (int i = 0; i < 8; i++)
{
if (map[si + dir[i][0]][sj + dir[i][1]] != '*')
{
map[si + dir[i][0]][sj + dir[i][1]] = '*';
dfs(si + dir[i][0], sj + dir[i][1]);
}
}
return;
}
int main()
{
while (cin >> m >> n&&(m||n))
{
for (int i = 1; i <= m;i++)
for (int j = 1; j <= n; j++)
cin >> map[i][j];
t = 0;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
{
if (map[i][j] == '@')
{
map[i][j] = '*';
t++;
dfs(i, j);
}
}
printf("%d\n", t);
}
return 0; }

HDU1241 Oil Deposits 2016-07-24 13:38 66人阅读 评论(0) 收藏的更多相关文章

  1. POJ1087 A Plug for UNIX 2017-02-12 13:38 40人阅读 评论(0) 收藏

    A Plug for UNIX Description You are in charge of setting up the press room for the inaugural meeting ...

  2. 百度地图-省市县联动加载地图 分类: Demo JavaScript 2015-04-26 13:08 530人阅读 评论(0) 收藏

    在平常项目中,我们会遇到这样的业务场景: 客户希望把自己的门店绘制在百度地图上,通过省.市.区的选择,然后加载不同区域下的店铺位置. 先看看效果图吧: 实现思路: 第一步:整理行政区域表: 要实现通过 ...

  3. Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏

    Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...

  4. IOS第三方数据库--FMDB 分类: ios技术 2015-03-01 09:38 57人阅读 评论(0) 收藏

    iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.PlausibleDatabase.sqlitepers ...

  5. Oracle错误IMP-00010: 不是有效的导出文件, 头部验证失败 分类: Oracle 2015-07-09 13:56 20人阅读 评论(0) 收藏

    Oracle 11g的dmp备份文件导入到Oracle 10g,出现错误信息: Import: Release 10.2.0.1.0 - Production on 星期四 7月 9 13:47:04 ...

  6. UI基础:UILabel.UIFont 分类: iOS学习-UI 2015-07-01 19:38 107人阅读 评论(0) 收藏

    UILabel:标签 继承自UIView ,在UIView基础上扩充了显示文本的功能.(文本框) UILabel的使用步骤 1.创建控件 UILabel *aLabel=[[UILabel alloc ...

  7. Hdu1969 Pie 2017-01-17 13:12 33人阅读 评论(0) 收藏

    Pie Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissio ...

  8. HDU1312 Red and Black(DFS) 2016-07-24 13:49 64人阅读 评论(0) 收藏

    Red and Black Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  9. HDU1237 简单计算器 2016-07-24 13:34 193人阅读 评论(0) 收藏

    简单计算器 Problem Description 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. Input 测试输入包含若干测试用例,每个测试用例占一行,每行不超过 ...

随机推荐

  1. xStream转换XML、JSON

        一. 简介 xStream可以很容易实现Java对象和xml文档互相转换, 可以修改某个特定的属性和节点名称,xStream提供annotation注解, 可以在JavaBean中完成对xml ...

  2. Ubuntu 安装 Elasticsearch

    1.安装java 注意:最新版本的elasticsearch(5.6.2)要求安装java8 1.sudo apt-add-repository ppa:webupd8team/java 2.sudo ...

  3. python生成器(转)

    生成器是一种特殊的迭代器,内部支持了生成器协议,不需要明确定义__iter__()和next()方法.生成器通过生成器函数产生,生成器函数可以通过常规的def语句来定义,但是不用return返回,而是 ...

  4. vmadm命令

    VMADM(1M)VMADM(1M) 名称 vmadm - 管理SmartOS虚拟机 概要 / usr / vm / sbin / vmadm <command> [-d] [-v] [特 ...

  5. GEOquery

    1)介绍 来自NCBI的Gene Expression Omnibus(GEO)作为各种高通量实验数据的公共存储库. 这些数据包括基于单通道和双通道微阵列的实验,测量mRNA,基因组DNA和蛋白质丰度 ...

  6. Redis 发布与订阅 消息

    基于Redis消息队列-实现短信服务化 1.Redis实现消息队列原理 常用的消息队列有RabbitMQ,ActiveMQ,个人觉得这种消息队列太大太重,本文介绍下基于Redis的轻量级消息队列服务. ...

  7. selenium IDE常用命令

    1.open(URL)命令                 1.作用:打开指定的URL,URL或者为相对或是绝对的URL                 2.target:要打开的URL,value值 ...

  8. Asp.net 后台调用js方法

    购物车实现逻辑简单.代码量也很少,具体细节就不说了,使用的时候,只要把MockDB类稍微改改,因为它是商品数据入口,为实现分布式部署,实际应用时可以更改为从服务调用,如:Web Service.WCF ...

  9. 【校招面试 之 C/C++】第8题 C++中的静态绑定与动态绑定

    转自:https://blog.csdn.net/chgaowei/article/details/6427731   做了部分修改 为了支持c++的多态性,才用了动态绑定和静态绑定.理解他们的区别有 ...

  10. C# .net MD5加密函数

    using System.Web.Security; string password =FormsAuthentication.HashPasswordForStoringInConfigFile(t ...