Oil Deposit
- 题目描述:
-
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的更多相关文章
- 题目1460:Oil Deposit(递归遍历图)
题目链接:http://ac.jobdu.com/problem.php?pid=1460 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 九度oj 题目1460:Oil Deposit
题目描述: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...
- Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Oil Deposits(dfs)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 2016HUAS暑假集训训练题 G - Oil Deposits
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- uva 572 oil deposits——yhx
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil d ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- hdu1241 Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) ...
- 杭电1241 Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission ...
随机推荐
- allure--下的各装饰器的翻译及自己的总结
翻译图-快捷键 红色字体感觉用的会比较多,起码现在感觉应该是比其他的多一点 lable应该没有什么特殊的用法,只是对下面方法的一个汇总(或者可以这么说,下面的方法是lable更具体的实现) sever ...
- 干货 | 揭秘如何增加listing多个类目节点
流量是电商销售的必要因素,可以说,任何成功的电商平台都离不开流量.亚马逊listing优化做得好,不仅能提高产品的曝光率,还能提升转换率,而好的类目可以吸引大的流量.帮你快速爬升. 首先我们来了解一下 ...
- 【HDU - 1429】胜利大逃亡(续) (高级搜索)【状态压缩+BFS】
Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带锁的门,钥匙藏在地牢另外的某些地方.刚开 ...
- mysql5.7 timestamp错误:there can be only oneTIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE
#1293 - Incorrect table definition; there can be only oneTIMESTAMP column with CURRENT_TIMESTAMP in ...
- JavaScript进阶系列1:performace和console.time性能测试
测试性能的时候,三种方法: 1.使用new Date() 返回整数值ms var dtStart=new Date(); for(var i=0;i<15000;i++){ i=i; } var ...
- ES9新内容概括
本文主要介绍ES2018 新出的一些特性 1.异步迭代 允许 async/await 与 for-of 一起使用,以串行的方式运行异步操作,达到异步函数的迭代效果. async function pr ...
- 在Windows Server 2012下安装 php memcache模块
一.环境描述 操作系统:Windows Server 2012 R2 Datacenter Web服务提供软件:Microsoft IIS 8.5.9600.16384 IIS调用PHP方法:增加处理 ...
- vue-实例生命周期钩子(不太明白)
每个 Vue 应用都是通过用 Vue 函数创建一个新的 Vue 实例开始的: var vm = new Vue({ // 选项}) 每个 Vue 实例在被创建时都要经过一系列的初始化过程——例如,需要 ...
- Previous operation has not finished;run 'cleanup' if it was interrupted;Please execute the 'Cleanup' command.
今天更新文件夹时svn报错如下 提示说让clean up,但是clean up又提示fail,让继续clean up,这样就陷入死循环了…… 搜了多种解决办法后找到原因:当时正在打开着svn的某个文件 ...
- linux php5.6 安装扩展 memcached
wget http://pecl.php.net/get/igbinary-1.1.1.tgz tar -xzvf igbinary-.tgz cd igbinary- /usr/local/php5 ...