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 ...
随机推荐
- xml 注释中不允许出现字符串“--“(再也不要来坑爹了,好么,XML)
转自:https://blog.csdn.net/randomnet/article/details/18708575?utm_source=blogxgwz3 关于xml文件时出现中文注释出错的一个 ...
- 与DispatcherServlet的 url-pattern配置问题
<!--当DispatcherServlet 的url-pattern配置成/ 访问不到静态资源 的解决方法1:使用Tomcat默认的Servlet解决 --> 在web.xml中加以下代 ...
- XML解析的二种方法之dom解析
XML解析的二种方法:dom解析和sax解析 文件大小 存储位置 读取速度 dom解析 小文件 放在内存中 快 sax解析 ...
- ArcEngine调用GP里的Merge工具传参问题
Merge工具inputs参数形式与Python中不同: string startLayerPath= cpj.TempWs.PathName + @"\" + datasetNa ...
- shader一般都是用工具调试的
N卡的话用nvidia的nVidia FX Composer, A卡的话用ATI的render monkey 顶点着色器从何方拿到这些数据?在U3D环境下,答案是从绑定到game object中的Me ...
- 解压*.tar.bz2的坑
下了一个压缩包,tar -xf 解压不了 解决办法: 装了bzip2工具 bzip2 -d **.tar.bz2 //将文件解压成**.tar tar -xf **.tar //解包 听说可以 tar ...
- dedecms实例化对象
1.建表 2.创建实体类 4.tc文件加载该实体类 5.用的时候,引入tc.php文件,并实例化
- SQL获取当前日期的年、月、日、时、分、秒数据
SQL Server中获取当前日期的年.月.日.时.分.秒数据: SELECT GETDATE() as '当前日期',DateName(year,GetDate()) as '年',DateName ...
- centos环境下输入命令不能有中文那么我怎么插入中文数据到数据库
centos环境下输入命令不能有中文那么我怎么插入中文数据到数据库 如下图: 首先查看是否安装了中文语言支持组件 yum grouplist 没有的话安装 yum install Chinese Su ...
- nginx 集群介绍
nginx 集群介绍 完成一次请求的步骤 1)用户发起请求 2)服务器接受请求 3)服务器处理请求(压力最大) 4)服务器响应请求 缺点:单点故障 单台服务器资源有限 单台服务器处理耗时长 ·1)部署 ...