Oil Deposits

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

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
 
DFS类型题
 #include<iostream>
#include<cstdio>
#define N 110
using namespace std; int m,n; int dir[][]={{-,-},{-,},{-,},{,-},{,},{,-},{,},{,}}; char maps[N][N]; int nx,ny; void dfs(int x,int y)
{ if(x<||x>=m||y<||y>=n)//判断当前所在位置是否合法;
return ;
if(maps[x][y]=='*')//递归结束条件;
return ;
else
{
maps[x][y]='*';
for(int i=;i<;i++)//搜索相邻的8个方向;
{
nx=x+dir[i][];
ny=y+dir[i][];
dfs(nx,ny);//进行深搜;
} }
} int main()
{
int i,j,ans; while(cin>>m>>n,m+n)
{
ans=; for(i=; i<m; i++)
scanf("%s",maps[i]);
for(i=; i<m; i++)
{
for(j=; j<n; j++)
{
if(maps[i][j]=='@')
{
dfs(i,j);
ans++;
}
}
}
printf("%d\n",ans);
}
return ;
}

hdu1241 Oil Deposits的更多相关文章

  1. HDU-1241 Oil Deposits (DFS)

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

  2. Hdu1241 Oil Deposits (DFS)

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

  3. HDU1241 Oil Deposits 2016-07-24 13:38 66人阅读 评论(0) 收藏

    Oil Deposits Problem Description The GeoSurvComp geologic survey company is responsible for detectin ...

  4. HDU1241 Oil Deposits —— DFS求连通块

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...

  5. 搜索专题:HDU1241 Oil Deposits

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

  6. HDU1241 - Oil Deposits【DFS】

    GeoSurvComp地质调查公司负责探测地下石油储藏. GeoSurvComp现在在一块矩形区域探测石油,并把这个大区域分成了很多小块.他们通过专业设备,来分析每个小块中是否蕴藏石油.如果这些蕴藏石 ...

  7. HDU1241 Oil Deposits(dfs+连通块问题)

    背景描述 ztw同志负责探测地下石油储藏.ztw现在在一块矩形区域探测石油.他通过专业设备,来分析每个小块中是否蕴藏石油.如果这些蕴藏石油的小方格相邻(横向相邻,纵向相邻,还有对角相邻),那么它们被认 ...

  8. Oil Deposits -----HDU1241暑假集训-搜索进阶

    L - Oil Deposits Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB   ...

  9. Oil Deposits( hdu1241

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/L Oil Deposits Time Limit:1000MS ...

随机推荐

  1. POJ 2117 (割点+连通分量)

    题目链接: http://poj.org/problem?id=2117 题目大意:在一个非连通图中,求一个切除图中任意一个割点方案,使得图中连通分量数最大. 解题思路: 一个大陷阱,m可以等于0,这 ...

  2. XCOJ 1102 (树形DP+背包)

    题目链接: http://xcacm.hfut.edu.cn/oj/problem.php?id=1102 题目大意:树上取点.父亲出现了,其儿子包括孙子...都不能出现.给定预算,问最大值. 解题思 ...

  3. 解决javax.imageio.IIOException: Can't create output stream!

    解决javax.imageio.IIOException: Can't create output stream! javax.imageio.ImageIO.write(image, "J ...

  4. VTK 5.10.1 VS2010 Configuration 配置

    Download VTK 5.10.1 Download VS2010 Download CMake 3.2.0 I assume you've already installed VS2010 an ...

  5. Qt connect parent widget 连接父控件的信号槽

    Qt中的信号槽系统是不同类中间传递数据的神器,如果连接父子空间之间的信号槽很重要,在父类中实例化子类的时候一定要注意将父类连上,不然信号槽无法使用,比如若子类是个对话框Dialog类,一定不要忘了加t ...

  6. [转] - JAR文件包及jar命令详解 ( MANIFEST.MF的用法 )

    常常在网上看到有人询问:如何把 java 程序编译成 .exe 文件.通常回答只有两种,一种是制作一个可执行的 JAR 文件包,然后就可以像. chm 文档一样双击运行了:而另一种是使用 JET 来进 ...

  7. ThinkPHP几个配置文件的位置

    1.常用的ThinkPHP\Conf\convention.php 2.ThinkPHP/Lib/Behavior/ParseTemplateBehavior.class.php模板引擎相关配置

  8. linux消息队列的使用及内核实现原理

    mq_receive NAME mq_open - open a message queue SYNOPSIS #include <fcntl.h> /* For O_* constant ...

  9. error while loading shared libraries: xxx.so.x" 错误的原因和解决办法

    今天在执行一个protobuf程序时,提示error while loading shared libraries: libprotobuf.so.8: cannot open shared obje ...

  10. PHP报错: Can't use method return value in write context

    $dp_id = $this->getParam('dpId'); if(!empty($this->getParam('dpId'))) { $this->smarty->a ...