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
- 1 1
- 样例输出:
-
- 0
- 1
- 2
- 2
- 0
- #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 ...
随机推荐
- springboot访问数据库(MySql)
1.使用JDBC访问数据库:JDBC是用于在Java语言编程中与数据库连接的API <dependency> <groupId>org.springframework.boot ...
- 铁大Facebook轻量化界面NABCD
界面轻量化: N:满足了用户更快速.更直接.更方便寻求自己所要信息的需求,不被复杂界面以及各种广告所困扰. A:我们将会用Bootstrap工具包开发前端界面,Bootstrap是基于jQuery框架 ...
- php无限极分类的实现
//指定根层级的树状图 function generateTree($list, $root = 0, $pk = 'id', $pid = 'pid', $child = '_child') { $ ...
- 现代 PHP 新特性 —— 生成器入门(转)
原文链接:blog.phpzendo.com PHP 在 5.5 版本中引入了「生成器(Generator)」特性,不过这个特性并没有引起人们的注意.在官方的 从 PHP 5.4.x 迁移到 PHP ...
- mpvue开发项目总结(从0到上线)
1.简言 为期一个半月的小程序开发,其中夹杂其他项目的功能迭代,跌跌撞撞的将项目完成了,今天中秋节放假前一天,以此来记录下此次打怪升级的心得与分享其中遇到花费时间的问题. 因为此次开发的是一个类电商项 ...
- json处理+list.sort()排序
#coding:utf-8 """ json是一种轻量级数据交换格式,可以对复杂数据进行表达和存储 规格: 1.数据保存在键值对里 2.键值对之间由逗号分隔 3.花括号用 ...
- JavaScript前端面试题总结
1.em和rem 像素(px):用于元素的边框或定位. em/rem:用于做响应式页面,em相对于父元素,rem相对于根元素. rem 单位翻译为像素值是由 html 元素的字体大小决定的. 此字体大 ...
- Spring框架中的定时器 使用和配置
Spring框架中的定时器 如何使用和配置 转载自:<Spring框架中的定时器 如何使用和配置>https://www.cnblogs.com/longqingyang/p/554543 ...
- 模仿WC.exe的功能实现--node.js
Github项目地址:https://github.com/102derLinmenmin/myWc WC 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要 ...
- flex布局-弹性布局
弹性布局当前应用的非常广泛,特别是移动端,记得第一次用reactNative 写代码的时候是最开始真正接触Flex布局.1.首先最外层的容器需要指定为display:flex;由于flex的兼容版本还 ...