Oil Deposits

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

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
 
Source
 
 
 
代码:
 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
char map[][];
int dir[][]={
{,},
{-,},
{,},
{,-},
{,},
{-,-},
{,-},
{-,}
};
int n,m;
void dfs(int st,int en)
{
for(int i=;i<;i++)
{
if(st+dir[i][]>=n&&st+dir[i][]<) continue;
if(en+dir[i][]>=m&&en+dir[i][]<) continue;
if(map[st+dir[i][]][en+dir[i][]]=='@')
{
map[st+dir[i][]][en+dir[i][]]='*';
dfs(st+dir[i][],en+dir[i][]);
}
}
}
int main()
{
int i,j,cnt;
while(scanf("%d%d",&n,&m),n+m)
{
cnt=;
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);
cnt++;
}
}
}
printf("%d\n",cnt);
}
return ;
}

HDUOJ---1241Oil Deposits(dfs)的更多相关文章

  1. HDU 1241Oil Deposits (DFS)

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

  2. hdu 1241Oil Deposits(dfs模板)

    题目链接—— http://acm.hdu.edu.cn/showproblem.php?pid=1241 首先给出一个n*m的字符矩阵,‘*’表示空地,‘@’表示油井.问在这个矩阵中有多少组油井区? ...

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

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

  4. poj - 2386 Lake Counting && hdoj -1241Oil Deposits (简单dfs)

    http://poj.org/problem?id=2386 http://acm.hdu.edu.cn/showproblem.php?pid=1241 求有多少个连通子图.复杂度都是O(n*m). ...

  5. Oil Deposits(dfs)

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

  6. HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)

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

  7. UVa572 Oil Deposits DFS求连通块

      技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...

  8. HDU 1241 Oil Deposits (DFS/BFS)

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

  9. HDU-1241 Oil Deposits (DFS)

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

  10. HDU_1241 Oil Deposits(DFS深搜)

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

随机推荐

  1. Spring Boot中application.yml与bootstrap.yml的区别(转)

    说明:其实yml和properties文件是一样的原理,主要是说明application和bootstrap的加载顺序.且一个项目上要么yml或者properties,二选一的存在. Bootstra ...

  2. Informatica 常用组件Lookup之五 转换属性

    查找转换的属性标识数据库源.PowerCenter 如何处理转换,以及它如何处理高速缓存和多项匹配. 创建映射时,为每个查找转换指定属性.创建会话时,您可在会话属性中覆盖某些属性,如每个转换的索引和数 ...

  3. go语言基础之append扩容特点

    1.append扩容特点 示例: package main //必须有个main包 import "fmt" func main() { //如果超过原来的容量,通常以2倍容量扩容 ...

  4. 动态装载外部JavaScript脚本文件

    当我们请求一个URL地址时,浏览器会从远程服务器装载各种所需的资源,如JavaScript.CSS.图片等.而在加载JavaScript时,常常会发生下面这种情况: 也就是说,当浏览器碰到Script ...

  5. IOS程式语法之block的使用掌握

    在现阶IOBlock 是iOS在4.0之后新增的程式语法,严格来说block的概念并不算是基础程式设计的范围,对初学者来说也不是很容易了解,但是在iOS SDK 4.0之后,block几乎出现在所有新 ...

  6. shell more less cat

    cat 连续显示.查看文件内容 more 分页查看文件内容 less 分页可控制查看文件内容 通俗点说: cat一次性把文件内容全部显示出来,管你看不看得清,显示完了cat命令就返回了,不能进行交互式 ...

  7. Android Studio安装&&安装bug

    1.安装SDK:Android SDK安装 2.安装Android Studio 3.配置HTTP Proxy: 转自:Android Studio设置HTTP代理(可用) 因为大陆的内网的防火墙很厉 ...

  8. 通过page页面与portlet的结合实现报表的局部刷新

    场景:系统已经存在两个报表,报表A与B,A与B之间可以通过省份进行追溯. 如下图:点击 报表[销售数据按区域]中的北京市 追溯到报表[销售数据按省份] 需求:让上面的操作在一个page里面刷新,实现页 ...

  9. kettle根据参数动态派生列

    抽取数据的时候没有日期字段,需要根据抽取日期自动生成月份,如下图结构 表输入_参数部分,接收来自其他系统传过来的参数(JAVA程序或者页面),具体设置如图 在查询数据时候派生列 运行模型的时候,给参数 ...

  10. (转)Unity中protobuf的使用方法

    在移动手机游戏开发中,目前Unity3D已成为比较主流的开发技术. 那么对于客户端服务器协议的打解包,我们有3中常用的处理方式: 1.自定义结构体:在协议中直接传输代码中自定义的结构体:这种方式的坏处 ...