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

Source

Mid-Central USA 1997 
 #include<stdio.h>
#include<iostream>
using namespace std;
int n,m;
char map[][];
int rx[]={,,,-,,,-,-};
int ry[]={,-,,,,-,,-};
void del(int i,int j)
{
map[i][j]='*';
int x,y,t;
for(t=;t<;t++)
{
x=i+rx[t];
y=j+ry[t];
if(x>=&&x<n&&y>=&&y<m&&map[x][y]=='@')
del(x,y);
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF&&n&&m)
{
int i,j,num=;
for(i=;i<n;i++)
for(j=;j<m;j++)
cin>>map[i][j];
for(i=;i<n;i++)
for(j=;j<m;j++)
if(map[i][j]=='@')
{
num++;
del(i,j);
}
printf("%d\n",num);
}
return ;
}

HDU 1241Oil Deposits (DFS)的更多相关文章

  1. hdu 1241Oil Deposits(dfs模板)

    题目链接—— http://acm.hdu.edu.cn/showproblem.php?pid=1241 首先给出一个n*m的字符矩阵,‘*’表示空地,‘@’表示油井.问在这个矩阵中有多少组油井区? ...

  2. hdu 1241Oil Deposits(BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...

  3. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  4. HDOJ(HDU).1015 Safecracker (DFS)

    HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...

  5. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  6. poj - 2386 Lake Counting && hdoj -1241Oil Deposits (简单dfs)

    http://poj.org/problem?id=2386 http://acm.hdu.edu.cn/showproblem.php?pid=1241 求有多少个连通子图.复杂度都是O(n*m). ...

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

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

  8. HDU 1241 Oil Deposits (DFS/BFS)

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

  9. HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题

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

随机推荐

  1. Windows 8 卡在正在检查更新

    原文地址:https://answers.microsoft.com/en-us/windows/forum/windows_8-update/windows-update-not-updating- ...

  2. 用linux 命令 执行ci框架的方法

    最近要跑一个数据量比较大的脚本,刚开始在浏览器页面访问发行nginx 5.4 超时, 又不想去修改nginx的连接时间,只能在服务器执行了, 执行方法:进入到ci 的根目录:#php index.ph ...

  3. 话说Angularjs的$resource模块

    上一篇中讲到使用$http同服务器进行通信,但是功能上比较简单,AngularJS还提供了另外一个可选的服务$resource,使用它可以非常方便的同支持restful的服务单进行数据交互. 安装 n ...

  4. Android Tips

    (1).设置图片缓存大小,一般可以设置为内存的1/8 int memoryCache = (int) (Runtime.getRuntime().maxMemory() / 8); (2). (3). ...

  5. 2014蓝桥杯问题 C: 神奇算式

    没做完,先搞答题了 #include <stdio.h> #include<string.h> #include<stdlib.h> int comp(const ...

  6. ascii 转换为 utf-8

    Python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错: UnicodeDecodeError: 'ascii' codec can't de ...

  7. ECMAScript6之Set结构和Map结构

    set数据结构 ES6提供了一个新的数据结构,Set,Set和Array数组相似,但是Set里没有重复的数据,可以说是一个值的集合. 同时,Set数据结构有以下属性和方法: size:返回成员总数 a ...

  8. WPS Office 二次开发简易教程。

    http://bbs.wps.cn/forum.php?mod=viewthread&tid=22004642

  9. zabbix 布署实践【5 使用邮箱SMTP SSL推送告警邮件】

    由于传统的邮件推送脚本使用smtp 25端口,在各大邮箱提供商已不适用,已经向SSL过渡,这里以QQ邮箱为例,使用SSL 465端口 登录zabbix-server 进入 cd /usr/lib/za ...

  10. CodeForces 706D Vasiliy's Multiset

    字典树. 比较经典的题目了.把每一个数字都插入到字典树中,询问的时候如果$x$的第$i$位是$p$,那么尝试着在字典树上往$pXOR1$的节点走下去,没有$pXOR1$节点的话再走$p$的.删除操作的 ...