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 <stdio.h>
char map[][];
int num,m,n;
void Dfs(int i,int j)
{
if(i>=&&i<=m&&j>=&&j<=n&&map[i][j]=='@')
{
map[i][j]='#';//记录走过之后不再复原路劲,表示这条路已经走过了
Dfs(i+,j);
Dfs(i-,j);
Dfs(i,j+);
Dfs(i,j-);
Dfs(i+,j+);
Dfs(i+,j-);
Dfs(i-,j-);
Dfs(i-,j+);
}
}
int main()
{
while(scanf("%d%d",&m,&n)!=EOF && m!=)
{
num=;
for(int i=;i<m;i++)
scanf("%s",map[i]);
for(int i=;i<m;i++)
for(int j=;j<n;j++)
if(map[i][j]=='@')
{
Dfs(i,j);
num++;
}
printf("%d\n",num);
}
}

HDU_1241——石油探索DFS的更多相关文章

  1. HDU_1241 Oil Deposits(DFS深搜)

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

  2. 【BZOJ3786】星系探索 DFS序+Splay

    [BZOJ3786]星系探索 Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为1号星球),其余的所有星球 ...

  3. bzoj 3786 星系探索 dfs+splay

    [BZOJ3786]星系探索 Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为1号星球),其余的所有星球 ...

  4. 【数据结构与算法Python版学习笔记】图——骑士周游问题 深度优先搜索

    骑士周游问题 概念 在一个国际象棋棋盘上, 一个棋子"马"(骑士) , 按照"马走日"的规则, 从一个格子出发, 要走遍所有棋盘格恰好一次.把一个这样的走棋序列 ...

  5. (DFS)HDU_1241 Oil Deposits

    HDU_1241 Oil Deposits   Problem Description The GeoSurvComp geologic survey company is responsible f ...

  6. 【BZOJ-3786】星系探索 Splay + DFS序

    3786: 星系探索 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 647  Solved: 212[Submit][Status][Discuss] ...

  7. hdu1242 Rescue DFS(路径探索题)

    这里我定义的路径探索题指 找某路能够到达目的地,每次走都有方向,由于是探索性的走 之后要后退 那些走过的状态都还原掉 地址:http://acm.hdu.edu.cn/showproblem.php? ...

  8. BZOJ3786 星系探索 【Splay维护dfs序】*

    BZOJ3786 星系探索 Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为1号星球),其余的所有星球均 ...

  9. 地下迷宫探索(dfs)

    地下迷宫探索(30 分) 地道战是在抗日战争时期,在华北平原上抗日军民利用地道打击日本侵略者的作战方式.地道网是房连房.街连街.村连村的地下工事,如下图所示. 我们在回顾前辈们艰苦卓绝的战争生活的同时 ...

随机推荐

  1. 自己主动生成材质Material(Unity3D开发之十九)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/46854411 ...

  2. Extjs4学习

    1 Ext js初步 1.1 获取Extjs 下载extjs: 可以从http://extjs.org.cn/ 获得需要的extjs发布包及更多支持. 1.2 搭建学习环境: 假设您的机器已经安装my ...

  3. C++学习笔记39:进程概念

    进程的基本概念 进程是描述程序执行过程和资源共享的基本单位 主要目的:控制和协调程序的执行 进程相关函数 用户与组ID函数 创建进程:system(),fork(),exec() 终止进程:kill( ...

  4. 使用SQL Server CONVERT() 函数

    语法 CONVERT(data_type(length),data_to_be_converted,style) data_type(length) 规定目标数据类型(带有可选的长度).data_to ...

  5. jQuery 基本实现功能模板

    下面是列出了基本功能的实现 <!DOCTYPE html> <html> <head> <script src="http://libs.baidu ...

  6. 查看SQL server服务名

    net start MSSQL$SQLEXPRESS 启动服务命令 net stop MSSQL$SQLEXPRESS 关闭服务命令 网上看到的那些 我都用不了 最后想起了这个 现在好了

  7. mysql死锁--源于外键关联

    死锁 存在于行级锁 存在的条件 1.资源只能同时被一个线程占有 2.资源占有不能被强制剥夺 3.请求和保持占有(在请求占有资源的同时能保持现有资源的占有) 4.死循环(一般做程序的人最关注的点) 一到 ...

  8. 几种破解MySQL root密码的几种方法:

    几种破解MySQL root密码的几种方法: 方法一 使用phpmyadmin,这是最简单的了,修改mysql库的user表,不过别忘了使用PASSWord函数. 方法二 使用mysqladmin,这 ...

  9. class类名的管理

    var a=document.querySelector(".div1"); a.classList.remove("div2");//减掉一个 a.class ...

  10. 完整版的strcpy函数

    char *strcpy(char *strDest,const char *strSrc) { assert((strDest!=NULL) && (strSrc!=NULL)); ...