题目描述:

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.

输入:

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.

输出:

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.

样例输入:
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
样例输出:
0
1
2
2
#include<iostream>
#include<stdio.h>
#include<queue>
using namespace std;
char maze[][];
bool mark[][];
int go[][]={
,,
-,,
,,
,-,
-,-,
,,
-,,
,-
};
int m,n;
void dfs(int x,int y){
for (int i=;i<;i++){
int nx=x+go[i][];
int ny=y+go[i][];
if (nx<||nx>=m||ny<||ny>=n) continue;
if (maze[nx][ny]=='*' || mark[nx][ny]==true) continue;
mark[nx][ny]=true;
dfs(nx,ny);
}
return;
} int main (){ while (cin>>m>>n && !(m==&&n==)){
for (int i=;i<m;i++){
//getchar();
for (int j=;j<n;j++){
//scanf("%c",maze[i][j]);
cin>>maze[i][j];
mark[i][j]=false;
}
} int ans=;
for (int i=;i<m;i++){
for (int j=;j<n;j++){
if (maze[i][j]=='*') continue;
if (mark[i][j]==true) continue;
dfs(i,j);
ans++;
}
}
cout<<ans<<endl;
} return ;
}

这种将相邻的点合成块的算法有一个专有名词,floodfill

Oil Deposit的更多相关文章

  1. 题目1460:Oil Deposit(递归遍历图)

    题目链接:http://ac.jobdu.com/problem.php?pid=1460 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  2. 九度oj 题目1460:Oil Deposit

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

  3. Oil Deposits

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

  4. Oil Deposits(dfs)

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

  5. 2016HUAS暑假集训训练题 G - Oil Deposits

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

  6. uva 572 oil deposits——yhx

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

  7. hdu 1241:Oil Deposits(DFS)

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

  8. hdu1241 Oil Deposits

    Oil Deposits                                                 Time Limit: 2000/1000 MS (Java/Others)  ...

  9. 杭电1241 Oil Deposits

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

随机推荐

  1. nrf52832板子焊接后总结的经验

    将之前打的nrf52832的板子拿到手了,经过一番焊接和调试后,发现了一些问题,因为是第一次画板焊接调试,很多地方做的不好,现在将自己的一些经验总结如下: 1 在制板之前,丝印层有必要好好的检查,建议 ...

  2. 给echart初始化的dom节点绑定时间获取点击的值渲染省市区

    this.drawMap().on('click', function (params) { var province = params.name; that.mapStatus = province ...

  3. scikit_learn lasso详解

    Lasso 回归 l1 正则化 The Lasso 是估计稀疏系数的线性模型. 它在一些情况下是有用的,因为它倾向于使用具有较少参数值的情况,有效地减少给定解决方案所依赖变量的数量. 因此,Lasso ...

  4. FPM三:简单的SEARCH(OIF)

    这里是使用FPM Workbench自动生成的,没有去SE80创建WDA程序. 1.使用事务代码:FPM_WB.打开工作台. 2.点击Wizard for Creating Empty FPM App ...

  5. python中对文件和文件夹的操作

    一.说明 python中主要通过os模块和shutil模块两个模块对文件进行相关操作,移动.复制.删除.重命名.比较大的文件通过命令操作可以节省时间,提高效率. 二.实例对文件夹中文件的拷贝 from ...

  6. 在idea中使用plantUML画类图

    1.下载插件,搜uml找找就有了,安装重启idea. 2.会提示你找不到graphviz,下载msi安装. 3.提示not executable,需要配置环境变量,不是配置path,配置GRAPHVI ...

  7. 小程序二层嵌套循环数据:微信小程序开发(交流QQ群:604788754)

    WXML: <view class="martop15"> <view class="titlebox"> .二层嵌套循环 </v ...

  8. 记一次腾讯云不能连接DNS服务器的问题排查过程

    由于腾讯云在使用过程中需要用到yum,在yum安装软件的时候报错不能连接到源的网站.当时经过排查发现域名没有解析.有可能是DNS服务器问题或者我的腾讯云DNS配置出现问题. 所以我查看了/etc/re ...

  9. Promise 错误处理

    Promise 是一个异步返回单个结果的函数或方法 不使用  `catch()` 时,在  `success handler` 里的错误无法被捕捉到 使用  `catch()` 时,在  `succe ...

  10. java第五次笔记