Oil Deposits 

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 and . 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.

 #include<cstdio>
#include<cstring>
int xx[]={-,-,-,,,,,},yy[]={-,,,-,,-,,},m,n;
bool map[][];
void dfs(int x,int y)
{
int i,j,k,p,q;
for (i=;i<=;i++)
{
p=x+xx[i];
q=y+yy[i];
if (p>=&&p<=m&&q>=&&q<=n&&map[p][q])
{
map[p][q]=;
dfs(p,q);
}
}
}
int main()
{
int i,j,k,p,q,ans;
char c,s[];
while (scanf("%d%d",&m,&n)&&m&&n)
{
memset(map,,sizeof(map));
gets(s);
for (i=;i<=m;i++)
{
gets(s+);
for (j=;j<=n;j++)
if (s[j]=='@')
map[i][j]=;
}
ans=;
for (i=;i<=m;i++)
for (j=;j<=n;j++)
if (map[i][j])
{
map[i][j]=;
dfs(i,j);
ans++;
}
printf("%d\n",ans);
}
}

每找到一个点,就将他DFS,标记掉所有周围的点。

uva 572 oil deposits——yhx的更多相关文章

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

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

  2. UVA 572 Oil Deposits油田(DFS求连通块)

    UVA 572     DFS(floodfill)  用DFS求连通块 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format: ...

  3. UVa 572 Oil Deposits(DFS)

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

  4. UVA - 572 Oil Deposits(dfs)

    题意:求连通块个数. 分析:dfs. #include<cstdio> #include<cstring> #include<cstdlib> #include&l ...

  5. Uva 572 Oil Deposits

    思路:可以用DFS求解.遍历这个二维数组,没发现一次未被发现的‘@’,便将其作为起点进行搜索.最后的答案,是这个遍历过程中发现了几次为被发现的‘@’ import java.util.*; publi ...

  6. UVa 572 - Oil Deposits (简单dfs)

    Description GeoSurvComp地质调查公司负责探測地下石油储藏. GeoSurvComp如今在一块矩形区域探測石油.并把这个大区域分成了非常多小块.他们通过专业设备.来分析每一个小块中 ...

  7. UVa 572 Oil Deposits (Floodfill && DFS)

    题意 :输入一个m行n列的字符矩阵,统计字符“@”组成多少个八连块.如果两个字符“@”所在的格子相邻(横竖以及对角方向),就是说它们属于同一个八连块. 分析 :可以考虑种子填充深搜的方法.两重for循 ...

  8. ACM:油田(Oil Deposits,UVa 572)

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

  9. Oil Deposits UVA - 572

    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...

随机推荐

  1. csharp:Dapper Sample

    You can find Dapper on Google Code here: http://code.google.com/p/dapper-dot-net/ and the GitHub dis ...

  2. 互联网产品团队中Web前端工程师的重要性

    国内外各大互联网公司,都有UEx/d|UCD|CDC(Customer Research & User Experience Design Center)团队. 在很多公司会认为,合格的产品经 ...

  3. PowerDesigner工具箱(palette)如何打开

    我使用的PowerDesigner是15.1版本的,其他版本的操作可能会有所不同 我们在使用PowerDesigner的时候,有时候可能会不小心把悬浮的工具箱隐藏掉,就是下面这个东西 怎么显示出来呢, ...

  4. 回文串---Hotaru's problem

    HDU   5371 Description Hotaru Ichijou recently is addicated to math problems. Now she is playing wit ...

  5. JavaScript基础11——js的全局函数

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. 拖拽改变div的大小

    拖拽改变div的大小 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&qu ...

  7. “连不上 ArcGIS License Manager ”的一点常用诊断方法

    在 ArcGIS Desktop 的问题库中,有一类不算做核心技术问题,但却可能会位列“最常见的问题”之一.简言之一句话,”许可服务器连不上怎么办?!“ 下面就来演绎下问题的诊断过程. 本文仅适用于客 ...

  8. Android NDK

    1.Android之NDK开发 http://www.cnblogs.com/devinzhang/archive/2012/02/29/2373729.html

  9. 关于android初学者必须掌握的Activity的四大知识点

    这几天一直都在捣鼓android的知识点,兴趣班的老师,讲课太过深奥,天(想到什么就见什么,后后面完全不想听),最后自己找资料总结了在Android学习中很重要的一个组件Activity,那就开始吧! ...

  10. App开发流程之通用宏定义及头文件

    工欲善其事,必先利其器. 在正式实现各种炫酷的功能和UI前,做好准备工作是提高后续开发效率的必经之路. 所以,这个系列,我不是在各种堆技术,更关注的是“兵马动”之前的“粮草行”,有些繁琐,但当清晰理出 ...