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
 
 
套模板,上代码:
 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
char map[][];
int vis[][];///标记数组
int dir[][]= {{,},{-,},{,},{,-},{,},{-,-},{,-},{-,}};///八面搜素
int n,m;
void DFS(int x,int y)
{
int a,b,i;
vis[x][y]=;
for(i=; i<; i++)
{
a=x+dir[i][];
b=y+dir[i][];
if(a>=&&a<n&&b>=&&b<m&&vis[a][b]==&&map[a][b]=='@')
{
DFS(a,b);
}
}
return ;
}
int main()
{
int count,i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
getchar();
if(n==&&n==)
break;
memset(map,,sizeof(map));
memset(vis,,sizeof(vis));
count=;
for(i=; i<n; i++)
{
scanf("%s",map[i]);
}
for(i=; i<n; i++)
{
for(j=; j<m; j++)
{
if(vis[i][j]==&&map[i][j]=='@')
{
count++;
DFS(i,j);
}
}
}
printf("%d\n",count);
}
return ;
}

Oil Deposits(DFS连通图)的更多相关文章

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

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

  2. Oil Deposits(dfs)

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

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

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

  4. UVa572 Oil Deposits DFS求连通块

      技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...

  5. HDU 1241 Oil Deposits (DFS/BFS)

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

  6. HDU-1241 Oil Deposits (DFS)

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

  7. HDU_1241 Oil Deposits(DFS深搜)

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

  8. UVa 572 Oil Deposits(DFS)

     Oil Deposits  The GeoSurvComp geologic survey company is responsible for detecting underground oil ...

  9. [POJ] 1562 Oil Deposits (DFS)

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16655   Accepted: 8917 Des ...

  10. Oil Deposits(dfs水)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...

随机推荐

  1. Java : Spring基础 AOP

    简单的JDK动态代理例子(JDK动态代理是用了接口实现的方式)(ICar是接口, GoogleCar是被代理对象, MyCC是处理方法的类): public class TestCar { publi ...

  2. vmware 虚拟机设置 redhat 桥接模式

    1.设置 vmware 网络模式 2.设置 linux 网络模式

  3. hadoop jobhistory访问界面长时间打不开

    1.浏览器无法直接通过url访问 可能原因 :主机名未配置,因此无法识别,在 c:\windows\system32\drivers\etc 目录添加主机名和对应ip hostname1[主机名 ] ...

  4. 第3章 Hadoop 2.x分布式集群搭建

    目录 3.1 配置各节点SSH无密钥登录 1.将各节点的秘钥加入到同一个授权文件中 2.拷贝授权文件到各个节点 3.测试无秘钥登录 3.2 搭建Hadoop集群 1.上传Hadoop并解压 2.配置H ...

  5. STM32F407+STemwin学习笔记之STemwin移植

    原文链接:http://www.cnblogs.com/NickQ/p/8748011.html 环境:keil5.20  STM32F407ZGT6  LCD(320*240)  STemwin:S ...

  6. mysql的数据类型与表约束

    数据类型 (详细数据类型请参考:http://www.runoob.com/mysql/mysql-data-types.html) 数字 整型  tinyint int bigint 小数: flo ...

  7. vuejs中使用v-model对表单数据的收集

    表单收集的信息针对有text/textarea,checkbox,radio,select 举个例子: <!DOCTYPE html> <html lang="en&quo ...

  8. FPGA软硬协同设计学习笔记及基础知识(一)

    一.FPGA软件硬件协同定义: 软件:一般以软件语言来描述,类似ARM处理器的嵌入式设计.硬件定义如FPGA,里面资源有限但可重配置性有许多优点,新的有动态可充配置技术. Xilinx开发了部分动态可 ...

  9. 阿里巴巴Java开发手册——速读记录

    本随笔基于阿里巴巴Java开发手册V1.2,陆陆续续记录一些现阶段能理解的,有启发的内容,并将持续更新 最佳实践——插件使用已经发布为随笔!http://www.cnblogs.com/jiangbe ...

  10. 将 List<Obj> 集合, 导出至 Excel

    主代码在这:http://www.codeproject.com/Articles/120480/Export-to-Excel-Functionality-in-WPF-DataGrid 黑人老外写 ...