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. win7 vs2010 安装cocos2d-x

    http://blog.csdn.net/leoncoder/article/details/12523727 新安装搭建cocos2d-X的跳过这里,看以下红色開始: cocos2d-x删除vs20 ...

  2. duilib DirectUI库里面的一个简单的例子RichListDemo

    1.首先来看这里的CRichListWnd 已经不再是从CWindowWnd继承了 classCRichListWnd:publicWindowImplBase 从WindowImplBase中,可以 ...

  3. Ternary Search Tree Java实现

    /** * @author Edwin Chen * */ //定义节点 class Node { //存储字符串 char storeChar; //是否完成单词 boolean isComplet ...

  4. .bash_profile和.bashrc的区别

    参考资料: http://blog.163.com/wang_hai_fei/blog/static/309020312008728333912/

  5. 【网络流#9】POJ 2135 Farm Tour 最小费用流 - 《挑战程序设计竞赛》例题

    [题意]给出一张无向图,从1开始到n,求两条没有公共边的最短路,使得路程总和最小 每条边的权值设为费用,最大流量设为1,然后就是从源点到汇点流量为2的最小费用流. 因为是规定了流量,新建一个源点和一个 ...

  6. 菜鸟学习Ado.net笔记一:Ado.net学习之SqlHelper类

    using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; usin ...

  7. Vs2010发布Asp.Net网站及挂到IIS服务上

    首先用vs2010打开一个Asp.Net项目, 也可以通过vs菜单->生成->发布网站                           选择发布网站的路径 这样发布就OK了 下面就吧发 ...

  8. CSS3 边框

    说明:CSS3完全向后兼容,因此不必改变现有的设计.浏览器通常支持CSS2 CSS3模块 CSS3被划分为模块: 选择器 框模型 背景和边框 文本效果 2D/3D 转换 动画 多列布局 用户界面 CS ...

  9. 安装VMware vCenter过程设置数据库方法

    VMware vCenter自带免费版的SQL Server 2005 Express,但此免费版数据库适合于小于5台ESX主机的小型部署.如果规模较大可以单独安装数据库系统进行配置,这里选择我独立安 ...

  10. Mysql中存储方式的区别

    MySQL的表属性有:MyISAM 和 InnoDB 2种存储方式: MyISAM 不支持事务回滚 InnoDB 支持事务回滚 可以用 show create table tablename 命令看表 ...