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. Arduino + SmartAirFilter 制作智能感应的 PM 空气净化器

    先说 SmartAirFilters 知道 SmartAirFilters 源自微博上转发的非常火的那个帖子,和动辄七八千元的商用产品比,几百元的 SmartAirFilters(下面简称电扇) 确实 ...

  2. 跟我学AngularJs:AngularJs入门及第一个实例

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:主要给大家介绍了AngularJs及其特性,并以3个实例来做说明. 本教程使用Angul ...

  3. C语言:通过函数指针来完成两个数的加减乘除(函数指针当做参数使用)

    // //  main.c //  Function_pointer // //  Created by mac on 15/8/2. //  Copyright (c) 2015年. All rig ...

  4. vb.net结构化异常处理和“邪用”

    vb.net中的错误处理包括两种:非结构化异常处理技术和结构化异常处理.非结构化异常处理技术在vb 6.0中使用的比较普遍,即通过Err对象和ON Error.Go To.Resume等语句来实现.这 ...

  5. 【Dagger2】 案例大全

    只有Inject是不可以的,必须有Component public class Test { @Inject Person person; private void test() { System.o ...

  6. 按示例学python:使用python抓取网页正文

    平时打开一个网页,除了文章的正文内容,通常会有一大堆的导航,广告和其他方面的信息.本博客的目的,在于说明如何从一个网页中提取出文章的正文内容,而过渡掉其他无关的的信息. 这里先看看 demo : ht ...

  7. POJ 2488 A Knight&#39;s Journey

    A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29226   Accepted: 10 ...

  8. WebRequest多线程 超时问题

    using System; using System.Collections; using System.Collections.Generic; using System.Net; using Sy ...

  9. [Node.js]23. Level 4: Semantic versioning

    Update the versions on your dependencies to be a little more flexible, adding the ~ in front of your ...

  10. OpenFace库(Tadas Baltrusaitis)中基于Haar Cascade Classifiers进行人脸检測的測试代码

    Tadas Baltrusaitis的OpenFace是一个开源的面部行为分析工具.它的源代码能够从 https://github.com/TadasBaltrusaitis/OpenFace 下载. ...