Oil Deposits
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20058 Accepted Submission(s): 11521
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.
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.
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.
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
1
2
2
#include <iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;
int n,m,sum;
][];
][],dir[][]= {,,,-,-,,-,-,,,,,,-,-,};//因为还有斜对角
void dfs(int x,int y)
{
int tx,ty;
;i<;i++)
{
tx=x+dir[i][];
ty=y+dir[i][];
|| tx>=n || ty< || ty>=m) continue;
if(mapt[tx][ty]=='@')//将其周围@的符号全部改为*,开始搜索
{
mapt[tx][ty]='*';
dfs(tx,ty);
}
}
}
int main()
{
while(scanf("%d%d",&n,&m),n,m)
{
int i,j;
memset(vis,,sizeof(vis));
; i<n; i++)
{
scanf("%s",mapt[i]);
}
sum=;
;i<n;i++)
{
;j<m;j++)
{
if(mapt[i][j]=='@')
{
mapt[i][j]='*';
dfs(i,j);
sum++;
}
}
}
printf("%d\n",sum);
}
;
}
Oil Deposits的更多相关文章
- 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< ...
随机推荐
- 深入剖析tomcat 笔记——第8章 载入器
深入剖析tomcat 笔记 目录:
- php时间设置为本地
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to ...
- Shell study note
td p { margin-bottom: 0in } p { margin-bottom: 0.1in; line-height: 120% } a:link { } 5.1 printenv vi ...
- μC/OS-Ⅲ系统的任务挂起表
在μC/OS-Ⅲ系统中任务挂起表与任务就续表十分相似,只不过任务就续表记录就绪状态的任务,任务挂起表记录等待某个内核对象的任务.任务挂起表是一个类型为OS_PEND_LIST的数据结构,包含三个成员: ...
- python cmd下运行中文乱码 策略
如我运行一个脚本,执行后输出中文看不懂 然后呢在文件头加上 from __future__ import unicode_literals 注意:需要去掉所有字符串前的 u, 这样所有字符串均默认为u ...
- C#中Thread与ThreadPool的比较
最近同事在编写一个基于UPD RTP协议的通信软件,在处理接收Listen时,发现了一个问题到底是用Thread还是ThreadPool呢? 我看同事的问题比较有典型性,还是做以整理培训一下吧 Thr ...
- VS2013 有效密钥
今天打开笔记本上的VS2013,发现试用版到期了,就到网上找密钥,找了一些时候找到一个有效序列号,记录如下: BWG7X-J98B3-W34RT-33B3R-JVYW9
- QT_BEGIN_NAMESPACE和QT_END_NAMESPACE的作用
本文根据在网上找到的一些资料总结来的,并加入了一些自己的想法. 在源代码中是这样定义的: # define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE { # ...
- RHEL6.4编译安装企业级LAMMP平台
一.LAMMP简介 二.使用软件及服务器架构说明 三.配置及安装过程 1.安装arp与httpd 2.安装mysql 3.安装php(php-fpm) 4.安装Xcache ...
- hudson slave搭建
Hudson Slave搭建 使用Hudson搭建分布式的构建环境非常方便,客户端也不需要太多的操作,只要能执行java命令就行. hudson默认采用master方式进行安装,master作为 ...