C - Oil Deposits(dfs)
Oil Deposits
Time
Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21383 Accepted Submission(s): 12319
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.
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
Select Code#include <stdio.h>
#include <iostream>
using namespace std; char s[102][102];
int m,n;
int i,j; void dfs(int x,int y)
{
if(x<1||x>m||y<1||y>n)
return ; // 函数返回值为空
if(s[x][y]!='@')
return ;
s[x][y]='*'; //标记
for(int i=-1 ; i<=1 ; i++)
for(int j=-1 ; j<=1 ; j++) //八个方向{ //也有另外一种写法 即用数组表示b[8][2]={{-1,0},{1,0},{0,-1},{0,1}
dfs(x+i,y+j); // ,{-1,1},{-1,-1},{1,1},{1,-1}}
}
}
int main()
{
while(cin>>m>>n&&m&&n) //这个地方的输入格式用这种,不用scanf
{
int c=0;
for(i=1 ; i<=m ; ++i)
for(j=1 ; j<=n ; j++)
{
cin>>s[i][j];
}
for(i=1 ; i<=m ; ++i)
for(j=1 ; j<=n ; ++j)
{
if(s[i][j]=='@')
{
dfs(i,j);
c++;
}
}
cout<<c<<endl; // return 0 ?
} }
这个题可以作为dfs的一个模板,通过这道题自己更加理解了dfs;
DFS + BFS // 深搜 || 广搜
http://blog.csdn.net/WYK1823376647/article/details/76376736
http://blog.csdn.net/WYK1823376647/article/details/76377050
http://blog.csdn.net/wyk1823376647/article/details/52062965
http://blog.csdn.net/wyk1823376647/article/details/52200485
http://blog.csdn.net/wyk1823376647/article/details/52739349
http://blog.csdn.net/wyk1823376647/article/details/52734432
http://blog.csdn.net/wyk1823376647/article/details/69214947
http://blog.csdn.net/wyk1823376647/article/details/52200580
C - Oil Deposits(dfs)的更多相关文章
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- Oil Deposits(dfs)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 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< ...
- HDU 1241 Oil Deposits (DFS/BFS)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU-1241 Oil Deposits (DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU_1241 Oil Deposits(DFS深搜)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- UVa 572 Oil Deposits(DFS)
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil ...
- [POJ] 1562 Oil Deposits (DFS)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16655 Accepted: 8917 Des ...
- Oil Deposits(dfs水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...
随机推荐
- 记一次微信小程序开发
之前在网上看到博客园新闻服务开放接口,因为自己本身有看博客园IT新闻的习惯,为了能随时随地简洁方便的浏览新闻,于是萌生了一个利用开放API开发一个微信小程序的想法. 1. mpvue初探 平时技术栈有 ...
- oracle 安装包
Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit ...
- zookeeper 节点讲解以及实际项目运用
转自:https://www.jianshu.com/p/86acf1df6cdd 前言:最近工作不是很忙,本应该乘着闲暇的时间看书的,之前每天晚上都要翻翻的,可是自己竟然迷恋上了王晓磊 写的 卑鄙的 ...
- 向ArcGIS的ToolBarControl中添加任意的windows组建的方法[转]
向ArcGIS的ToolBarControl中添加任意的windows组建的方法[转] Link: http://www.cnblogs.com/mymhj/archive/2012/10/12/27 ...
- css常用属性总结:文本属性中的text-align
前面提到text-indent属性,用来实现文本的缩进,今天的text-align使用率可比文本缩进高的多.拿自己现在做的项目上来说,水平居中和垂直居中估计是用到最多了,那我们就先看看它的语法吧! t ...
- flask test
DATABASE_URI = 'mysql://root:mhc.123@127.0.0.1/test1'
- socket的protocal参数
Documentation for socket() on Linux is split between various manpages including ip(7) that specifies ...
- [z]微信平台开发教程
http://blog.csdn.net/lyq8479?viewmode=contents
- msdn 硬盘
https://msdn.microsoft.com/library/windows/hardware/ff566204 Returns the ATA-2 identify data, the Se ...
- [在职软件工程]基于CMMI的软件工程教程
第1章 软件工程基础 1.1软件工程基本原理 a.按照软件生命周期的阶段划分制定计划,严格依据计划进行管理 项目概要计划,里程碑计划,项目控制计划,产品控制计划,验证计划,运行维护计划 b.坚持进行阶 ...