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. Python变量和字符串详解

    Python变量和字符串详解 几个月前,我开始学习个人形象管理,从发型.妆容.服饰到仪表仪态,都开始做全新改造,在塑造个人风格时,最基础的是先了解自己属于哪种风格,然后找到参考对象去模仿,可以是自己欣 ...

  2. mvc中@RenderSection()研究 转载https://www.cnblogs.com/rrxc/p/4062827.html

    一.@RenderSection定义 HelperResult RenderSection(string name) 但是当如果使用了_Layout.cshtml做母版页的页没有实现Section的话 ...

  3. socket选项总结(setsockopt)

    功能描述:        获取或者设置与某个套接字关联的选 项.选项可能存在于多层协议中,它们总会出现在最上面的套接字层.当操作套接字选项时,选项位于的层和选项的名称必须给出.为了操作套接字层的选项, ...

  4. PS总结

    1.ALT:取消工具选择状态2. photoshopcs6 出现因为智能对象不能直接进行编辑    解决方案:右击---图层名---栅格化图层3.Shift+F5:填充画布颜色 4.PS不能变换路径, ...

  5. jQuery基础--总结

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  6. Pikachu漏洞练习平台实验——越权漏洞(八)

    1.概述 由于没有对用户权限进行严格的判断 导致低权限的账号(比如普通用户)可以去完成高权限账号(比如超管)范围内的操作 水行越权:A用户和B用户属于同一级别用户,但各自不能操作对方个人信息.A用户如 ...

  7. linux下shell显示git当前分支

    function git-branch-name { git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 } functio ...

  8. sql片段的定义

    <!-- sql片段 id 表示唯一标示 这里不加where是因为 sql片段只对单表查询才抽取出来 这样的重用性更高 --> <sql id="query_user_wh ...

  9. python学习第十七天字符串的创建和操作方法

    字符串也是任何编程语言最常见的编程语言,字符串是有序的,可以通过下标来访问,可以切片,可以查找,可以替换,字符串可以和列表之间互相转换 join() split() 等函数 1,字符串的创建 单引号 ...

  10. IIS 应用池资源定时回收

    方法1: 方法2: