Oil Deposits
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.
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.
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
#include
#define maxn 110
using namespace std;
char mapn[maxn][maxn];
int
direction[8][2]={{-1,0},{1,0},{0,1},{0,-1},{-1,-1},{-1,1},{1,-1},{1,1}};
bool visit[maxn][maxn];
int m,n,sum=0;
bool isbound(int a,int b)//判断边界
{
if(a<1||a>m||b<1||b>n)return true;
return
false;
}
dfs(int x,int y)
{
for(int
i=0;i<8;i++)
{
if(mapn[x+direction[i][0]][y+direction[i][1]]=='*')
continue;
if(isbound(x+direction[i][0],y+direction[i][1]))
continue;
if(visit[x+direction[i][0]][y+direction[i][1]])
continue;
visit[x+direction[i][0]][y+direction[i][1]]=true;
dfs(x+direction[i][0],y+direction[i][1]);
}
}
main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d\n",&m,&n)&&(m||n))//这地方应该有一个回车
{
//printf("m=%d n=%d\n",m,n);
memset(visit,false,sizeof(visit));
sum=0;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
scanf("%c",&mapn[i][j]);
}
scanf("\n");//每行输入结束都应该有一个回车
}
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
if(mapn[i][j]=='@'&&!visit[i][j])
{
dfs(i,j);
visit[i][j]=true;
sum++;
}
}
printf("%d\n",sum);
}
}
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 ...
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- UVa572 Oil Deposits DFS求连通块
技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...
随机推荐
- RabbitMQ消息队列之一:RabbitMQ的环境安装及配置
RabbitMQ简介: MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们 ...
- 最详细的PHP flush()与ob_flush()的区别详解
buffer ---- flush()buffer是一个内存地址空间,Linux系统默认大小一般为4096(1kb),即一个内存页.主要用于存储速度不同步的设备或者优先级不同的 设备之间传办理数据的区 ...
- WPA/WPA2加密破解
WPA/WPA2无线密码破解这里主要介绍两种方法:穷举PIN码.穷举密码 穷举PIN码(共11000种组合)破解速度快,需要一些条件(路由器支持WPS.QSS功能),路由器信号良好.无论密码多复杂,条 ...
- js Date() 浏览器兼容问题解决
一般 直接new Date() 是不会出现兼容性问题的,而 new Date(datetimeformatstring) 常常会出现浏览器兼容性问题,为什么,datetimeformatstring中 ...
- 【DDD】领域驱动设计实践 —— Application层实现
本文是DDD框架实现讲解的第二篇,主要介绍了DDD的Application层的实现,详细讲解了service.assemble的职责和实现.文末附有github地址.相比于<领域驱动设计> ...
- 关于C++中char 型变量的地址输出
在刚开始学习C/C++过程中,我们希望输出各个变量的地址来窥探一些我们"百思不得其解"的现象,例如搞清函数堆栈相关的程序内部秘密. 先看下面示例: #include<stdi ...
- 动易CMS - 设为首页代码和加入收藏代码(兼容各种浏览器)
注意: 这里虽然说是兼容,但是有些浏览器的设置就是不支持用js来把页面设为首页,加入收藏夹,只能让用户手动去在浏览器或者按键去设置这些功能,这里说的兼容是指当浏览器有这个设置的时候js会有提示. ...
- 7-21(排序) PAT排名汇总
计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科学的评价计算机程序设计人才, ...
- TCP/IP(五)传输层(TCP的三次握手和四次挥手)
前言 这一篇我将介绍的是大家面试经常被会问到的,三次握手四次挥手的过程.以前我听到这个是什么意思呀?听的我一脸蒙逼,但是学习之后就原来就那么回事! 一.运输层概述 1.1.运输层简介 这一层的功能也挺 ...
- jquery模板下载网站
jquery模板下载网站 http://www.jqshare.com/