Oil Deposits

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

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
 
简单的搜索题  和南阳的 水池数目差不多  只不过增加了 四个方向的搜索
/*
题意:给你一个规格为n*m的矩阵,由
字符'@'和'*'组成,问所有的@组成的区域
有多少块,(@组成的区域指向它的八个方向中其中一个方向
走依然是@)
题解:先找到第一个@,然后向这个@的八个方向查找,将所有查找到的
@都替换为*(将找过的位置覆盖,避免重复查找),看最后调用了dfs函数
多少次,就有多少个区域
*/ #include<stdio.h> ///hdu1241
#include<string.h>
#include<algorithm>
#define MAX 110
#define INF 0x3f3f3f
char map[MAX][MAX];
int n,m;
void dfs(int x,int y)
{
int i,j;
int move[8][2]={1,0,-1,0,0,1,0,-1,1,-1,1,1,-1,1,-1,-1};
if(map[x][y]=='@'&&0<=x&&x<n&&0<=y&&y<m)
{
map[x][y]='*';
for(i=0;i<8;i++)//搜索八个方向
dfs(x+move[i][0],y+move[i][1]);
//可以用上边的辅助数组进行搜索 ,也可以直接按照下边注释的
//方法搜索,其原理相同
// dfs(x-1,y);
// dfs(x+1,y);
// dfs(x,y-1);
// dfs(x,y+1);
// dfs(x-1,y-1);
// dfs(x-1,y+1);
// dfs(x+1,y-1);
// dfs(x+1,y+1);
}
return ;
}
int main()
{
int j,i,t,k;
while(scanf("%d%d",&n,&m),n|m)
{
for(i=0;i<n;i++)
scanf("%s",map[i]); int sum=0;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(map[i][j]=='@')
{
dfs(i,j);
sum++;
}
}
}
printf("%d\n",sum);
}
return 0;
}

  

  

hdoj 1241 Oil Deposits的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. HDOJ/HDU 1241 Oil Deposits(经典DFS)

    Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...

  7. hdu 1241:Oil Deposits(DFS)

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

  8. 杭电1241 Oil Deposits

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

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

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

随机推荐

  1. BZOJ 2124等差子序列 线段树&&hash

    [题目描述 Description] 给一个 1 到 N 的排列{Ai},询问是否存在 1<=p1<p2<p3<p4<p5<…<pLen<=N(Len& ...

  2. 蓝桥杯——FJ字符串

    FJ在沙盘上写了这样一些字符串: A1 = "A"1 A2 = "ABA"3 A3 = "ABACABA"7 A4 = "ABAC ...

  3. hdu 3333 Turing Tree 图灵树(线段树 + 二分离散)

    http://acm.hdu.edu.cn/showproblem.php?pid=3333 Turing Tree Time Limit: 6000/3000 MS (Java/Others)    ...

  4. HDU 1160 FatMouse's Speed(DP)

    点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...

  5. POJ2302

    简单题. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm ...

  6. 运行edX Devstack

    前一篇文章,我们安装完成了edX Devstack,本文将介绍edX Devstack的常用命令 6.1. 连接到 Devstack Virtual Machine 为了连接到Devstack vir ...

  7. jav利用反射修改类的静态变量

    有Student这个类: public class Student { private static String schoolName=""; private static St ...

  8. spring+mybatis 框架搭建

    注意<!-- 中间的字要保持与左右留出一个空格,否则会报错说出现两杠线 --> 1.导入jar包 aopalliance-1.0.jarasm-3.3.1.jarcglib-2.2.2.j ...

  9. ANDROID_MARS学习笔记_S01原始版_012_广播机制一

    一.简介 二.代码1.xml(1)activity_main.xml <?xml version="1.0" encoding="utf-8"?> ...

  10. Linux网络地址转换分析

    Linux网络地址转换分析 地址转换用来改变源/目的端口,是netfilter的一部分,也是通过hook点上注册相应的结构来工作. Nat注册的hook点和conntrack相同,只是优先级不同,数据 ...