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. javascript 基础1第11节

    <html> <head> <title>javascript基础</title> </head> <body> 1.NaN i ...

  2. Codevs 1225 八数码难题

    1225 八数码难题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Yours和zero在研究A*启发式算法.拿到一道经典的 ...

  3. OpenCV(2)-Mat数据结构及访问Mat中像素

    Mat数据结构 一开始OpenCV是基于C语言的,在比较早的教材例如<学习OpenCV>中,讲解的存储图像的数据结构还是IplImage,这样需要手动管理内存.现在存储图像的基本数据结构是 ...

  4. How to say all the keyboard symbols in English and Chinese

    How to say all the keyboard symbols in English Symbol English 中文 ~ tilde 波浪号 ` grave accent, backquo ...

  5. js获取url的get传值函数

    function getvl(name) { var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s| ...

  6. node.js操作mongoDB数据库

    链接数据库: var mongo=require("mongodb"); var host="localhost"; var port=mongo.Connec ...

  7. TDirectory.IsEmpty判断指定目录是否为空

    使用函数: System.IOUtils.TDirectory.IsEmpty class function IsEmpty(const Path: string): Boolean; static; ...

  8. ios 网络字节顺序的转换HTOS

    最近用socket发送data遇到个问题,字节高地位和服务器不匹配,搞了好久才找到解决的方案,主要用到两个函数HTOL HTOS STOH LTOL 故写此博文 什么是字节序 采用维基百科的解释如下: ...

  9. VS2010升级VS2012必备(MVC4 WebPage2.0 Razor2.0资料汇集)

    刚把项目升级到2012,发现发生了很多变化,以下是最近看过的网站和资料汇集,供需要者参考. 本文在最近一个月可能会不断更新. Razor2.0 新特性介绍: 介绍1:http://vibrantcod ...

  10. SVN - 基础知识

    1. 术语 $ svn checkout  URL [PATH] -----   下载服务器所有文件 (clone) 到本地[path]  --- 只需一次 $ svn checkout  http: ...