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. iOS svn版本回退 cornerstone

    http://blog.csdn.net/x32sky/article/details/46866899   IOS开发中,SVN如何恢复到某一个版本(以Cornerstone为例) Cornerst ...

  2. HDU 4628 Pieces(DP + 状态压缩)

    Pieces 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4628 题目大意:给定一个字符串s,如果子序列中有回文,可以一步删除掉它,求把整个序列删除 ...

  3. leetcode344——Reverse String(C++)

    Write a function that takes a string as input and returns the string reversed. Example:Given s = &qu ...

  4. cocos2d-x使用DragonBones动画

    前言 在网上查找关于DragonBones在cocos2d-x的使用教程,找了大半天也没有找到一个有用的.在自己摸索了一段时间终于摸索了出来,在这里记下分享给大家. 下载DragonBones 我这里 ...

  5. 下载youku视频(python3)

    https://github.com/chenfengyuan/download-youku-video 用tornado写的下载脚本, 从flvcd.com得到下载地址. 因为我这边连youku的速 ...

  6. 怎样用AIDL Service 传递复杂数据

    大家都知道在Android中通过AIDL可以跨进程调用Service中的数据,网上也有很多实例,但是大部分实例都是关于基本数据类型的远程调用,很少讲到复杂数据的调用,今天我用一个例子来演示一下怎样用A ...

  7. 如何设置 font-family 比较好以及字体的中英文名

    如何设置 font-family 比较好? 如果设置为font-family: Arial, "微软雅黑","宋体"; 是不是英文都会使用Arial字体,而中文 ...

  8. J2EE中的HttpSession

    J2EE中的HttpSession总结: ①什么是session? session是服务器端技术,利用这个技术,服务器在运行时可以为每一个浏览器创建一个共享的session对象,由于 session为 ...

  9. Eyeshot Ultimate 学习笔记(3)

    实体角度和位置的控制 有时候导入的模型方向或者角度不太适合,就需要调节一下,这里我发现的一种方法是用到Transformation类,其实有很多类的运用都非常灵活,如果不是有官方示例,恐怕是很难发现的 ...

  10. Python小杂点

    1.函数调用 a = [] def fun(a): a.append(1) print (a) 这个时候输出的结果为[],如果想要出现1,需要先运行函数fun,然后在输出a 2.python方法 de ...