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. Android企业级程序完全退出的解决方案

    一.问题描述 在平常开发的过程中可以发现,很多开发者对于程序的退出都没有去认真的解决.一般要么是一个简单的finish(只是退出当前的activity),要么是其他的方法,比如: 1.第一种方法:首先 ...

  2. Java第三周学习日记

    Day01 1.线程 进程:进程就是正在运行的应用程序.进程负责了内存空间的划分. 线程:一个进程中的代码是由线程去执行的,线程也就是其中一个执行路径. 多线程:一个进程中有多个线程可以同时执行任务. ...

  3. jquery之提示信息

    //生成优惠券并分发 function saveCouponAssign(){ //发行券种 var couponTypeId = $("#couponTypeId").combo ...

  4. HTTP 503 错误 – 服务不可用 (Service unavailable)

    介绍 因暂时超载或临时维护,您的 Web 服务器目前无法处理 HTTP 请求. 其含义是, 这是一个暂时情况,会有一些延误, 过 后将会得到缓解. 有些服务器在这种情况下也许干脆拒绝套接字(socke ...

  5. visifire 图表属性样式设置说明,字体,阴影设置

  6. silverlight 双坐标轴

    public void CreateLine(Grid oGrid, string sTitle, string sTableName, bool ifGetSig, string sYUint, s ...

  7. 用pod导入ReactiveCocoa

    用pod导入ReactiveCocoa [1]   第一种 platform:ios,'7.0' pod 'ReactiveCocoa' [2]  第二种 pod 'ReactiveCocoa','2 ...

  8. 加载gif图过渡效果

    加载gif图片,过渡效果: 调用: - (id)initWithGifView:(UIView *)view { self = [super initWithView:view]; if (self) ...

  9. java递归删除指定目录下的文件和文件夹

    public static boolean deleteFolder(String delDir) { File delFolder = new File(delDir); File[] delFil ...

  10. 【JAVA编码专题】深入分析 Java 中的中文编码问题

    http://www.ibm.com/developerworks/cn/java/j-lo-chinesecoding/ 几种常见的编码格式 为什么要编码 不知道大家有没有想过一个问题,那就是为什么 ...