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< ...
随机推荐
- 20169212《Linux内核原理与分析》课程总结
20169212<Linux内核原理与分析>课程总结 每周作业链接汇总 第一周作业:完成linux基础入门实验,了解一些基础的命令操作. 第二周作业:学习MOOC课程--计算机是如何工作的 ...
- 深入springMVC源码------文件上传源码解析(下篇)
在上篇<深入springMVC------文件上传源码解析(上篇) >中,介绍了springmvc文件上传相关.那么本篇呢,将进一步介绍springmvc 上传文件的效率问题. 相信大部分 ...
- postgres 正则表达式 转
http://blog.csdn.net/wugewuge/article/details/7704996 postgresql中使用正则表达式时需要使用关键字“~”,以表示该关键字之前的内容需匹配之 ...
- Mysql Innodb 引擎优化-内存、日志、IO、其他相关参数
介绍: InnoDB给MySQL提供了具有提交,回滚和崩溃恢复能力的事务安全(ACID兼容)存储引擎.InnoDB锁定在行级并且也在SELECT语句提供一个Oracle风格一致的非锁定读.这些特色增加 ...
- css3实现逐渐变大的圆填充div背景的效果
手机端现在的一些应用会运用上这样一个效果,就是duang的一下出现一个圆变大直到填充整个div,动感十足. 想到css3的scale属性,就自己来实现一下. <div id="bcd& ...
- Linux 下使用Visual Studio Code
1.下载:https://az764295.vo.msecnd.net/stable/db71ac615ddf9f33b133ff2536f5d33a77d4774e/VSCode-linux-x64 ...
- WCF传输图片解决方案
图片无法序列化后传输,但我们可以将图片转二进制字符串传输.然后在服务端将二进制字符串转图片. 将图片转字符串的例子: private byte[] BmpToJpegBuff(Image img) { ...
- STM32时钟数
在STM32中,有五个时钟源,为HSI.HSE.LSI.LSE.PLL. 其实是四个时钟源,如下图所示(灰蓝色),PLL是由锁相环电路倍频得到PLL时钟. ①.HSI是高速内部时钟,RC振荡器,频率为 ...
- memset函数详解
语言中memset函数详解(2011-11-16 21:11:02)转载▼标签: 杂谈 分类: 工具相关 功 能: 将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值, 块的大 ...
- truncate,delete,drop的异同点
说明:本文摘自oracle技术用户讨论组 truncate,delete,drop的异同点 注意:这里说的delete是指不带where子句的delete语句 相同点:truncate和不带w ...