http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/L
Oil Deposits

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cmath> using namespace std; #define N 110 char maps[N][N];
int m, n; void DFS(int o, int p);
int dir[][] = { {-,-},{-,},{-,},{,-},{,},{,-},{,},{,}}; int main()
{
int i, j, cou; while(cin >> m >> n, m+n)
{
cou = ; for(i = ; i < m; i++)
cin >> maps[i]; for(i = ; i < m; i++)
for(j = ; j < n; j++)
{
if(maps[i][j] == '@')
{
cou++;
DFS(i, j);
}
} cout << cou << endl;
} return ;
} void DFS(int o, int p)
{
int i, q, w; maps[o][p] = '*'; for(i = ; i < ; i++)
{
q = o + dir[i][];
w = p + dir[i][]; if(q >= && q < m && w >= && w < n && maps[q][w] == '@')
DFS(q, w);
}
}

Oil Deposits( hdu1241的更多相关文章

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

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

  2. UVA 572 -- Oil Deposits(DFS求连通块+种子填充算法)

    UVA 572 -- Oil Deposits(DFS求连通块) 图也有DFS和BFS遍历,由于DFS更好写,所以一般用DFS寻找连通块. 下述代码用一个二重循环来找到当前格子的相邻8个格子,也可用常 ...

  3. 【HDU - 1241】Oil Deposits(dfs+染色)

    Oil Deposits Descriptions: The GeoSurvComp geologic survey company is responsible for detecting unde ...

  4. hdu 1241:Oil Deposits(DFS)

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

  5. ZOJ 1709 Oil Deposits(dfs,连通块个数)

    Oil Deposits Time Limit: 2 Seconds      Memory Limit: 65536 KB The GeoSurvComp geologic survey compa ...

  6. Oil Deposits (HDU - 1241 )(DFS思路 或者 BFS思路)

    转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82706189作者:Mercury_Lc 题目链接 题解:每个点(为被修改,是#)进 ...

  7. 暑假集训(1)第七弹 -----Oil Deposits(Poj1562)

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

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

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

  9. hdu 1241 Oil Deposits (简单搜索)

    题目:   The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...

随机推荐

  1. Linux-磁盘配额

    磁盘配额作用是限制普通用户使用的磁盘空间和创建文件的个数,不至于因为个别人的浪费而影响所有人的使用,需要内核的支持 注意:目前只有 ext2 ext3文件系统支持 需要用户程序quota程序包 先查看 ...

  2. java 工厂模式 从无到有-到简单工厂模式-到工厂方法模式-抽象工厂模式

    工厂模式定义(百度百科): 工厂模式是我们最常用的实例化对象模式了,是用工厂方法代替new操作的一种模式.著名的Jive论坛 ,就大量使用了工厂模式,工厂模式在Java程序系统可以说是随处可见.因为工 ...

  3. php难不难?

    php难不难?多久能学会? 我认为php难不难学和php多久学会是一个共性问题,所以我们首先来总结下有那么几种情况. 好的情况: 1.不排除有的人有天赋.智商高脑仁大.上手很快,这个和脑仁中的Z字回形 ...

  4. Django CORS跨域资源共享

    1,什么是CORS ​ 允许浏览器向跨源(协议 + 域名 + 端口)服务器发出XMLHttpRequest请求,从而克服了AJAX只能同源使用的限制 2,特点 ​ 1,浏览器自动完成(在请求头中加入特 ...

  5. [NOIP2016]借教室

    NOIP2012提高组D2T2. 这道题目非常基础,正解貌似是二分+差分数组,在这里提供一种线段树的思路. 很容易发现题目让我们每次修改一段区间,然后我们只需要看每一个区间内有没有负数就可以了.可以用 ...

  6. JVM(15)之 类加载器

    开发十年,就只剩下这套架构体系了! >>>   今天我们将类加载机制5个阶段中的第一个阶段,加载,又叫做装载.为了便于阅读,以下都叫做装载.    装载的第一步就是要获得二进制的字节 ...

  7. Spring学习笔记(14)——SpEL

    是什么 Spring表达式语言全称为"Spring Expression Language",缩写为"SpEL",类似于Struts2x中使用的OGNL表达式语 ...

  8. RDD缓存

    RDD的缓存 Spark速度非常快的原因之一,就是在不同操作中可以在内存中持久化或缓存数据集.当持久化某个RDD后,每一个节点都将把计算的分片结果保存在内存中,并在对此RDD或衍生出的RDD进行的其他 ...

  9. 为什么需要在 React 类组件中为事件处理程序绑定this?

    https://juejin.im/post/5afa6e2f6fb9a07aa2137f51 事件绑定作为回调函数参数传递给函数,丢失其上下文,执行的是默认绑定,不是隐式绑定 类声明和类表达式的主体 ...

  10. samba - 为 UNIX 实现的 Windows SMB/CIFS 文件服务器

    SYNOPSIS 总览 Samba DESCRIPTION 描述 samba 套件是在 UNIX 系统上实现“服务器信息块”(通常简称 SMB) 协议的一组程序.这个协议有时也称为“通用互联网文件系统 ...