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 ...
随机推荐
- 使用npm私有服务器保存公司内部强业务类型组件(二):vue-webpack框架
一套基于vue webpack element-ui的npm私有服务器开发组件框架 下载 在配置的有两个地方需要注意: 1:配置library library选项: 如果设置此选项,会将bundle导 ...
- classList用法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python爬虫-入门-了解爬虫
作为一个爬虫新手,我觉得首先要了解爬虫是的作用以及应用. 作用:通过爬虫获取网页内的信息.包括:标题(title)图片(image)链接(url)等等 应用:抽取所需信息,进行数据汇总及分析(从事网页 ...
- 如何正确可视化RAW(ARW,DNG,raw等格式)图像?
为了正确可视化RAW图像,需要做好:白平衡.提亮以及色彩映射. import numpy as np import struct from PIL import Image import rawpy ...
- ReactJS之遍历对象的方法
const obj = { channel: “wevmvmklskdosll12k;0”, index:0 }; Object.keys(obj).map(key => console.log ...
- 备忘:移植ucos-III到stm32f103c8t6
由于本人对linux系统内核这块比较感兴趣,下一份工作想做linux驱动相关的:于是最近一旦有空都在研究linux内核源码,面对linux内核这个庞然大物,越看越觉得不能太过急躁,且由于还要工作,只能 ...
- Python3+slowloris安装使用教程
一.说明 今天提到slowloris,这东西看着很眼熟,应该是以前局方打算用来刷竞赛积分的工具.我总觉得DoS没什么意思,但记不得怎么用了所以还是研究一下. 二.安装 slowloris就是一个pyt ...
- mysql查询表字段名称,字段类型
select column_name,column_comment,data_type from information_schema.columns where table_name='查询表名称' ...
- 1.moocs
“三巨头”:Coursera.edX和Udacity Coursera:http://www.coursera.org 目前发展最大的MOOCs平台,拥有相近500门来自世界各地大学的课程,门类丰富, ...
- HDU1237
/************************************************************** 作者:陈新 邮箱:cx2pirate@gmail.com 用途:hdu1 ...