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. windows server 2008镜像重启后密码变为默认密码的问题的解决方案

    1. cmd中执行regedit,打开注册表: 修改HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cloudbase Solusions\Cloudbase-Init ...

  2. 选择第n小的元素之python实现源码

    def partition(A, p, r): j = p+1 for i in range(p+1, r+1): if(A[i] < A[p]): tmp = A[i] A[i] = A[j] ...

  3. Linux内核设计与实现 读书笔记

    第三章 进程管理 1. fork系统调用从内核返回两次: 一次返回到子进程,一次返回到父进程 2. task_struct结构是用slab分配器分配的,2.6以前的是放在内核栈的栈底的:所有进程的ta ...

  4. 【原创】Linux编译内核

    Linux 编译内核 大致分这几个步骤 1.准备编译工具.内核文件 2.开始编译 3.将编译好的新内核install进系统 4.查看是否成功.   一.准备好必备的库和内核文件   1.添加必备的编译 ...

  5. $.ajax参数备注-转转转

    jquery中的ajax方法参数总是记不住,这里记录一下.  $,ajax()方法参数详解 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为St ...

  6. InkPicture 控件使用_01

    private System.ComponentModel.Container components = null;  private Microsoft.Ink.InkOverlay m_InkOv ...

  7. thinkPHP add、save无法添加、修改不起作用

    案例:数据库新添加一字段,修改值不成功.解决方案:将Runtime/Data/_fields/下面的字段缓存删除,或者直接删除整个Runtime文件也是可以的分析:由于Thinkphp,采用字段缓存机 ...

  8. PHP构造函数的用法分析

    PHP构造函数的声明与其它操作的声明一样,只是其名称必须是__construct( ).这是PHP5中的变化,以前的版本中,构造函数的名称必须与类名相同,这种在PHP5中仍然可以用,但现在以经很少有人 ...

  9. 禁止生产pyc

    sys.dont_write_bytecode = 1 来自为知笔记(Wiz)

  10. 解决windows下eclipse中android项目关联android library project

    关于 在项目中导入 关联 library project 的问题,有时候会出现如下状况 在windows系统下,library project必须和project处于相同的盘符中 如果在不同盘符,pr ...