Oil Deposits

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

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
 

思路:深搜dfs,不难,但是注意细节,积累经验。

#include<stdio.h>
char str[][];
int
d[][]={,,,-, -,, -,-,,,,-,,, -,};
int
m,n;
void
dfs(int x,int y)
{

str[x][y] = '*';
int
i,nx,ny;
for
(i =;i <=;i ++)
{

nx = x+d[i][];
ny = y+d[i][];
if
(nx > - && nx < m && ny > - && ny < n && str[nx][ny] == '@')
dfs(nx,ny);
}

return
;
}
int main()
{

int
t,k,cnt;
while
(~scanf("%d%d",&m,&n)&&m)
{

cnt =;
for
(t =;t < m;t ++)
scanf("%s",str[t]);
for
(t =;t < m;t ++)
{

for
(k =;k < n;k ++)
{

if
(str[t][k] == '@')
{

dfs(t,k);
cnt++;
}
}
}

printf("%d\n",cnt);
}

return
;
}

DHU-1241 Oil Deposits的更多相关文章

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

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

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

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

  3. HDU 1241 Oil Deposits(石油储藏)

    HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Probl ...

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

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

  5. DFS(连通块) HDU 1241 Oil Deposits

    题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...

  6. hdu 1241:Oil Deposits(DFS)

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

  7. 杭电1241 Oil Deposits

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

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

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

  9. HDU 1241 Oil Deposits (DFS/BFS)

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

  10. hdoj 1241 Oil Deposits

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

随机推荐

  1. 类库探源——System.Drawing.Bitmap

    一.System.Drawing.Bitmap Bitmap 类: 封装GDI+ 位图,此位图由图形图像及其属性的像素数据组成.Bitmap 是用于处理由像素定义的图像的对象 命名空间: System ...

  2. phaser源码解析(一) Phaser.Utils类下shuffle方法

    /** * #一个 基于 费雪耶茨排列 洗牌方法 * A standard Fisher-Yates Array shuffle implementation. * @method Phaser.Ut ...

  3. 怎么安装MySQL,安装MySQL遇到的一些问题!!!!!!

    简介: 对于初学,我们在安装MySQL时,会出现各种各样的报错,这让我们非常的头痛.那么我来分享一下我在安装的过程中遇到的一些问题吧! 我们在安装MySQL之前,先安装好dotNetFx40_Clie ...

  4. Spring 对JDBC的支持(JdbcTemplate)

    Spring对数据库的操作,使用JdbcTemplate对象 需要引入相关的jar文件 如版本:(Spring核心jar包就不列了) spring-jdbc-3.2.5.RELEASE.jar spr ...

  5. Shell脚本——DNS自动部署

    详细说明查看: (一)跟我一起玩Linux网络服务:DNS服务——BIND(/etc/named.conf./var/named)设置实现和解释 #! /bin/bash IP="10.10 ...

  6. 【原创】Linux opensource-src-4.3.2.tar.gz的安装。

    下载好opensource-src-4.3.2.tar.gz 安装G++等必备库: sudo apt-get install make gcc g++ sudo apt-get install bui ...

  7. 【原创】Android开发使用华为手机调试logcat没有应用输出信息

    输入 *#*#2846579#*#* 点击project Menu点击后台 1.设置logcat 2. Dump & Log",打开开关"打开Dump & Log& ...

  8. emment语法

    emment插件语法.md 元素 div → <div></div>foo → <foo></foo> 嵌套运算符 子: > div>ul& ...

  9. 欢迎使用skymvc框架,简单易用的php框架

    skymvc是一款轻量.简单易用的php mvc框架,经过多个项目实践改良. 特点: 1.mvc架构 2.m.v.c之间可以互相调用 3.简单的路由控制 R("/index.php" ...

  10. TDirectory.IsRelativePath是否相对路径

    使用函数: System.IOUtils.TDirectory.IsRelativePath class function IsRelativePath(const Path: string): Bo ...