题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241

Oil Deposits

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18650    Accepted Submission(s): 10750

Problem Description
The
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
The
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.
 
Output
For
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.
 
Sample Input
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
 
Sample Output
0
1
2
2
 
Source
 
题目很好理解 及用dfs求联通块
代码:
 #include<cstdio>
#include<cstring>
using namespace std;
#define N 105
char mp[N][N];
bool vis[N][N];
int n, m;
bool in(int i , int j )
{
if(i < n&&i>=&&j<m&&j>=) return true;
else return false;
}
int go[][] = {{,},{,},{,},{-,},{-,},{-,-},{,-},{,-}};
void dfs(int i , int j)
{
if(in(i, j)&&mp[i][j]=='@'&&!vis[i][j])
{
vis[i][j] = ;
for(int t = ;t < ; t++)
{
int x = i + go[t][];
int y = j + go[t][];
dfs(x,y);
}
}
}
int main()
{
while(~scanf("%d%d",&n,&m)&&(n!=||m!=))
{
getchar();
for(int i = ;i < n ;i++)
{
for(int j = ; j < m ; j++){
scanf("%c",&mp[i][j]);
vis[i][j] = ;
}
getchar();
}
int cnt = ;
for(int i = ;i < n ; i++)
{
for(int j = ;j < m ;j++)
{
if(mp[i][j]=='@'&&!vis[i][j])
{
cnt++;
dfs(i,j);
}
}
}
printf("%d\n",cnt);
}
return ;
}

Oil Deposits(dfs水)的更多相关文章

  1. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  2. HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题

    Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil de ...

  3. Oil Deposits(dfs)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  4. HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  5. UVa572 Oil Deposits DFS求连通块

      技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...

  6. HDU 1241 Oil Deposits (DFS/BFS)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. HDU-1241 Oil Deposits (DFS)

    Oil Deposits Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  8. HDU_1241 Oil Deposits(DFS深搜)

    Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...

  9. UVa 572 Oil Deposits(DFS)

     Oil Deposits  The GeoSurvComp geologic survey company is responsible for detecting underground oil ...

随机推荐

  1. JaveScript流程控制(JS知识点归纳四)

    01 流程控制 顺序结构: 程序的默认执行方式 条件判断语句:也称之为分支结构,选择结构:如果程序要执行的代码出现了多种情况需要使用 循环结构:当代码需要多次重复执行多次时,使用 02 条件判断语句 ...

  2. GDB scheduler-locking 命令详解

    GDB scheduler-locking 命令详解 GDB> show scheduler-locking     //显示线程的scheduler-locking状态GDB> set ...

  3. async和enterproxy控制并发数量

    聊聊并发与并行 并发我们经常提及之,不管是web server,app并发无处不在,操作系统中,指一个时间段中几个程序处于已经启动运行到完毕之间,且这几个程序都是在同一处理机上运行,并且任一个时间点只 ...

  4. redis hash结构 遍历某一个key下所有的(field,values)的方法

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/95 redis的hash结构中存储了如下的数据: $input ...

  5. [C#]使用Quartz.NET来创建定时工作任务

    本文为原创文章.源代码为原创代码,如转载/复制,请在网页/代码处明显位置标明原文名称.作者及网址,谢谢! 开发工具:VS2017 语言:C# DotNet版本:.Net FrameWork 4.0及以 ...

  6. C++中double类型的数字如何保留三位小数点详解

    我们知道C语言中,如果要求输出结果保留三位小数,我们可以使用pritf()函数轻松的解决.但是C++的输出运算符<<并没有直接实现这个功能,怎么办呢?之前在找答案的过程中各路大神给出了千姿 ...

  7. vmware workstation14永久激活密钥分享

    vmware workstation14永久激活密钥分享 VMware Workstation是一款功能强大的桌面虚拟计算机软件,简单来说就是最强的中文虚拟机了,可以在桌面上运行不同的操作系统,下面就 ...

  8. Xamarin.Android 使用Timer 并更改UI

    http://blog.csdn.net/ozhangsan12345/article/details/72653070 第一步:创建timer对象 //创建timer对象 Timer _dispat ...

  9. Linux文件的复制、删除和移动命令

    cp命令  功能:将给出的文件或目录拷贝到另一文件或目录中,就如同DOS下的copy命令一样,功能非常强大.  语法:cp [选项] 源文件或目录 目标文件或目录  说明:该命令把指定的源文件复制到目 ...

  10. vexx 邀请码 送3个比特龙

    错过了比特币的行情,注册获取3个原始比特币分叉币,比特龙. 目前10元一个,送3个币.类似于股票IPO,第一天一般会冲高十几倍,建议第一天就卖. 如果看好就继续持有吧. 放心是送的不用钱的. 注册网址 ...