链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1241

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18758    Accepted Submission(s): 10806

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 <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue> using namespace std; #define N 110 char Map[N][N];
int n, m, dir[][]={{-,-},{-,},{-,},{,-},{,},{,-},{,},{,}}; void DFS(int x, int y)
{
if(Map[x][y]=='*')
return ;
if(x< || x>=n || y< || y>=m)
return ; Map[x][y] = '*'; for(int i=; i<; i++)
DFS(x+dir[i][], y+dir[i][]);
} int main()
{ while(scanf("%d%d", &n, &m), n+m)
{
int i, j, sum=; for(i=; i<n; i++)
scanf("%s", Map[i]); for(i=; i<n; i++)
for(j=; j<m; j++)
{
if(Map[i][j]=='@')
{
DFS(i, j);
sum ++;
}
}
printf("%d\n", sum);
}
return ;
}

(深搜)Oil Deposits -- hdu -- 1241的更多相关文章

  1. Oil Deposits HDU - 1241 (dfs)

    Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...

  2. Oil Deposits HDU 1241

    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...

  3. kuangbin专题 专题一 简单搜索 Oil Deposits HDU - 1241

    题目链接:https://vjudge.net/problem/HDU-1241 题意:问有几个油田,一个油田由相邻的‘@’,组成. 思路:bfs,dfs都可以,只需要遍历地图,遇到‘@’,跑一遍搜索 ...

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

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

  5. HDU 1241 Oil Deposits --- 入门DFS

    HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...

  6. HDOJ/HDU 1241 Oil Deposits(经典DFS)

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

  7. hdu 1241 Oil Deposits(DFS求连通块)

    HDU 1241  Oil Deposits L -DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & ...

  8. 深搜基础题目 杭电 HDU 1241

    HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...

  9. hdu 1241 Oil Deposits (简单搜索)

    题目:   The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...

随机推荐

  1. 【ZedGraph】右键菜单和鼠标滚轴的移动缩放等功能的启用和禁用 (转)

    通过[ZedGraph]控件属性修改: 1.禁用右键菜单: IsShowContextMenu = false; 2.禁用鼠标滚轴移动: IsEnableHPan = false; //禁止横向移动; ...

  2. APN与VPDN的主要区别

    VPDN APN 安全性 二次认证,加密 一次认证,没有加密 企业成本 高 低 对GGSN要求 可接受动态配置LNS参数信息,对GGSN性能影响小. 静态配置GRE隧道参数,性能影响较大,部分厂家对G ...

  3. 错误 1 缺少编译器要求的成员“System.Runtime.CompilerServices.ExtensionAttrib

    错误 1 缺少编译器要求的成员“System.Runtime.CompilerServices.ExtensionAttrib 删除Newtonsoft.Json.dll 引用 ,再重新引用即可. 原 ...

  4. 启动zookeeper时,jps显示有进程,但是status查看状态时就Error contacting service. It is probably not running

    转自:http://www.cnblogs.com/xiaohua92/p/5460515.html#undefined 安装zookeeper时候,可以查看进程启动,但是状态显示报错:Error c ...

  5. charles手机抓包配置-1

    1.下载和安装Charles 下载和安装Charles软件.安装前要先安装Java运行环境,因为Charles是Java写的. 自己百度云上有破解版 2.安装电脑的Charles证书,对证书进行信任设 ...

  6. Python将数据写入excel或者txt,读入csv格式或xls文件,写入csv(写一行空一行解决办法)

    1.写入excel,一开始不需要自己新建一个excel,会自动生成 attribute_proba是我写入的对象 import xlwt myexcel = xlwt.Workbook() sheet ...

  7. Windows 10 修改系统环境变量后,CMD生效,Powershell未生效

    Windows 10 修改系统环境变量后 1.CMD重新打开,新环境变量已经生效: 2.Shift+右键Powershell重新打开,新环境变量没有生效: 3.貌似服务(Apache24)中使用的环境 ...

  8. pythonNet08

    线程通信 通信方法:多个线程共用进程空间,所以进程的全局变量对进程内线程均可见.线程往往使用全局变量进行通信 注意事项:线程间使用全局变量进行通信,全局变量为共享资源,往往需要同步互斥机制 线程的同步 ...

  9. django-上下文渲染器,将后端内容提供给模板使用,自定义渲染器

    使用场景:当同一个类容需要出现在多个模板中, 上下文管理器就是将这个内容以字典的形式返回给所有模板,模板通过 {{ key }}取值. 结构:上下文管理器 文件名一般为context_processo ...

  10. Python实践练习:将一个文件夹备份到一个 ZIP 文件

    题目 项目要求:假定你正在做一个项目,它的文件保存在 C:\AlsPythonBook 文件夹中.你担心工作会丢失, 所以希望为整个文件夹创建一个 ZIP 文件, 作为"快照" . ...