HDU 1241 :Oil Deposits
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11360 Accepted Submission(s): 6626
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.
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.
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
0
1
2
2
从每一个“@”格子出发,递归遍历它周围的“@”格子。。再将其改为“*”。结果加一。
这是一道经典的DFS。。
非常easy的。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; const int M = 100 + 5; int m, n;
int sum;
char oil[M][M];
int dx[8]= {1,1,1,0,0,-1,-1,-1};
int dy[8]= {0,1,-1,1,-1,1,0,-1}; void dfs( int x, int y )
{
int i, xx, yy;
for(i=0; i<8; i++ )
{
xx = x + dx[i];
yy = y + dy[i];
if(xx<0 || xx>=m || yy<0 || yy>=n) //边境
continue;
if(oil[xx][yy] == '*')
continue;
oil[xx][yy] = '*';
dfs( xx, yy );
}
} int main()
{
int i, j;
while(~scanf("%d%d", &m, &n)&&m&&n)
{
sum = 0;
for(i=0; i<m; i++)
scanf("%s", oil[i]);
for(i=0; i<m; i++)
for(j=0; j<n; j++)
{
if(oil[i][j] == '@')
{
dfs( i, j );
sum++;
}
}
printf("%d\n",sum);
}
return 0;
}
HDU 1241 :Oil Deposits的更多相关文章
- 【HDU - 1241】Oil Deposits(dfs+染色)
Oil Deposits Descriptions: The GeoSurvComp geologic survey company is responsible for detecting unde ...
- POJ 1562:Oil Deposits
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14462 Accepted: 7875 Des ...
- HDU 1241 Oil Deposits (DFS)
题目链接:Oil Deposits 解析:问有多少个"@"块.当中每一个块内的各个"@"至少通过八个方向之中的一个相邻. 直接从"@"的地方 ...
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...
- hdu 1241 Oil Deposits(DFS求连通块)
HDU 1241 Oil Deposits L -DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & ...
- (深搜)Oil Deposits -- hdu -- 1241
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- DFS(连通块) HDU 1241 Oil Deposits
题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...
- Oil Deposits HDU - 1241 (dfs)
Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...
随机推荐
- 从零开始学C++之异常(一):C语言错误处理方法、C++异常处理方法(throw, try, catch)简介
一.C语言错误处理方法 1.返回值(if … else语句判断错误) 2.errno(linux 系统调用) 3.goto语句(函数内局部跳转) 4.setjmp.longjmp(Do not use ...
- JDK 安装以及环境变量的配置(Windows)
首先下载对应版本的jdk ,然后安装,这里使用的是jdk 1.7的安装的 这个时候,JDK 已经安装完成,打开cmd 输入 java -version 就可以查看到,当前JDK 的版本如图 JDK 安 ...
- window2003远程桌面“已达最大连接数”
使用命令行强制注销远程登录用户 Fri, 04/19/2013 - 09:29 - admin 来源地址: http://space.itpub.net/10067101/viewspace-6147 ...
- Servlet过滤器——日志记录过滤器
1.概述 在实际的项目开发过程中,经常需要在项目运行时,记录并在控制台中输出运行时的日志信息,便于查看项目的运行状况.本实例将介绍如何应用过滤器实现日志记录.运行本实例,将在控制台中输出项目运行时的日 ...
- C++STL之set容器及stream类
首先讲stream流类 头文件#include <sstream> 其功能是进行不同类型之间的转换,跟C语言 fscanf 和 fprintf 作用是同样的,可是比C语言的更简便更好用. ...
- [Machine Learning (Andrew NG courses)]IV.Linear Regression with Multiple Variables
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenFoXzE5OTE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...
- 5350.support
3G6200N3G6200NL3G300MAIR3GIIALL02393GALL0256NALL5002ALL5003ARGUS_ATP52B,ASL26555AWM002EVBAWAPN2403BC ...
- [iOS]简单的APP引导页的实现 (Swift)
在第一次打开APP或者APP更新后通常用引导页来展示产品特性 我们用NSUserDefaults类来判断程序是不是第一次启动或是否更新,在AppDelegate.swift中加入以下代码: func ...
- [C#基础] 类
类成员 字段和方法是最重要的类成员类型,字段是数据成员,方法是函数成员 字段 字段是隶属于类的变量 它可以是任何类型,无论是预定义类型还是用户定义类型 和所有变量一样,字段用来保存数据 它们可以被写入 ...
- NetBSD是个开源到源码的系统
How to get NetBSD NetBSD is an Open Source operating system, and as such it is freely available for ...