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

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

0122

```#include <stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
char map[101][101];
int n, m, p;
void dfs(int i, int j)//递归函数
{
if(map[i][j]!='@' || i<0 || j<0 || i>=m || j>=n) return;
else
{
map[i][j]='*';//扫过的都变成'*'
dfs(i-1, j-1);
dfs(i-1, j);
dfs(i-1, j+1);
dfs(i, j-1);
dfs(i, j+1);
dfs(i+1, j-1);
dfs(i+1, j);
dfs(i+1, j+1);
}
}
int main()
{
int i, j;
while(scanf("%d%d",&m,&n)!=EOF)
{
if(m==0 || n==0) break;
p = 0;
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
//scanf("%c",&map[i][j]);
cin>>map[i][j];
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
if(map[i][j] == '@')
{
dfs(i, j);
p++;
}
}
}
printf("%d\n",p);
}

return 0;
}
```

## poj1562--Oil Deposits的更多相关文章

1. poj1562 Oil Deposits 深搜模板题

题目描述: Description The GeoSurvComp geologic survey company is responsible for detecting underground o ...

2. poj1562 Oil Deposits（DFS）

题目链接 http://poj.org/problem?id=1562 题意 输入一个m行n列的棋盘,棋盘上每个位置为'*'或者'@',求'@'的连通块有几个(连通为8连通,即上下左右,两条对角线). ...

3. 暑假集训(1)第七弹 -----Oil Deposits（Poj1562)

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

4. Oil Deposits

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

5. Oil Deposits(dfs)

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

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

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

7. uva 572 oil deposits——yhx

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

8. hdu 1241:Oil Deposits（DFS）

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

9. hdu1241 Oil Deposits

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

10. 杭电1241 Oil Deposits

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

## 随机推荐

1. SDWebImage使用及原理

第一步,下载SDWebImage,导入工程.github托管地址https://github.com/rs/SDWebImage 第二步,在需要的地方导入头文件 1 #import "UII ...

2. Charles

1. charles使用教程指南+客户端弱网测试:http://blog.csdn.net/anualday/article/details/51423457 2.使用Charles对Https请求进 ...

3. hdu 2648 Shopping

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2648 纯暴力的方法T_T... 如下: #include<cstdio> #include ...

4. 所有 HTTP 状态代码及其定义

所有 HTTP 状态代码及其定义. 代码  指示  2xx  成功  200  正常:请求已完成.  201  正常:紧接 POST 命令.  202  正常:已接受用于处理,但处理尚未完成.  20 ...

5. PHP 常用字符串函数

1.查找字符位置函数 strpos(\$str,search,[int]):查找search在\$str中的第一次位置从int开始: stripos(\$str,search,[int]):函数返回字符串在 ...

6. [Swift]LeetCode113. 路径总和 II | Path Sum II

Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...

7. 记录一下我在lubuntu里面用到的工具

文本编辑:Atom 文本对比:Beyond Compare 数据库工具:dbeaver Git工具:GitKraKen SVN工具:RapidSVN 网页编程工具:WebStorm 另外,14.04版 ...