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 ...
随机推荐
- DB2 日期时间函数
db2日期时间函数 (DATE(TRIM(CHAR(DT#11Y))||'-'||TRIM(CHAR(DT#11M))||'-'||TRIM(CHAR(DT#11D))) BETWEEN DATE(' ...
- 为何在JDK安装路径下存在两个JRE?
"两个jre"和"三个lib"的功能简单扼要的解释 安装JDK后,Java目录下有jdk和jre两个文件夹,但jdk下还有一个jre文件夹,而且这个jre比前面 ...
- 小菜鸟入门nginx
实现功能:端口进行转发 比如我实际运行的是·http:localhost:5000 但是我想通过localhost:80 进行访问. 过程 1 下载nginx 2 解压到某个目录(比如我放在C盘根目录 ...
- python's nonlocal
[python's nonlocal] nonlocal是python3.x中新加的关键字,用于引用本作用域外层作用域的名字 参考:http://blog.csdn.net/chain2012/art ...
- 获取set()和push()方法向值栈放的数据
------------------siwuxie095 获取 set() 方法向值栈放的数据 1.具体步骤 (1)在 Action 中使用 set() 方法向值栈放数据 (2)在 JSP 页面中从值 ...
- SQL Server判断数据库、表、存储过程、函数是否存在
--判断数据库是否存在 if exists (select * from sys.databases where name = '数据库名') drop database [数据库名] --判断表是否 ...
- 深入理解那该死的BOM
BOM(Byte Order Mark),是UTF编码方案里用于标识编码的标准标记,在UTF-16里本来是FF FE,变成UTF-8就成了EF BB BF.这个标记是可选的,因为UTF8字节没有顺序, ...
- Java 设计模式系列(五)原型模式
Java 设计模式系列(五)原型模式 原型模式属于对象的创建模式.通过给出一个原型对象来指明所有创建的对象的类型,然后用复制这个原型对象的办法创建出更多同类型的对象.这就是选型模式的用意. 一.原型模 ...
- Android使用ListView使用方法
Android使用ListView应该注意的地方 在ListView中设置Selector为null会报空指针? mListView.setSelector(null);//空指针 试试下面这种: ...
- IndexedDB:浏览器里内置的数据库(转)
出处;http://www.webhek.com/indexeddb/ IndexedDB是HTML5规范里新出现的浏览器里内置的数据库.对于在浏览器里存储数据,你可以使用cookies或local ...