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. HTMl5/CSS3/Javascript 学习推荐资源

    HTMl5/CSS3/Javascript 学习推荐资源 前端的定义应该是数据内容的展示,在国内大家都觉得前端只是HTML+CSS+Javascript,但是实际上与展示有关的都是前端,所以Ruby/ ...

  2. [转]单例模式——C++实现自动释放单例类的实例

    [转]单例模式——C++实现自动释放单例类的实例 http://www.cnblogs.com/wxxweb/archive/2011/04/15/2017088.html http://blog.s ...

  3. JBPM4.4学习API

    一.流程引擎API org.jbpm.api.ProcessEngine是jbpm4所有的Service API 之源. 既所有的Service API(服务接口)都从ProcessEngine中获取 ...

  4. java--测体重练习

    public class tz{ public static void main(String[] args){ int sg=165,tz=52;bz = sg-115 if (tz-bz>3 ...

  5. windows实时操作系统

    最近一个项目需要用windows进行实时定时操作以实现同步功能(12ms),不过由于windows是分时系统,其可供用户使用的定时器误差较大. 通过查找发现了一个ardence公司开发的一个叫做RTX ...

  6. RAID 容量计算器

    https://www.synology.com/zh-cn/support/RAID_calculator   磁盘阵列比较表   n/2 n/2 n n/2 安全性高 综合RAID 0/1优点,理 ...

  7. 【iHMI43 4.3寸液晶模块】demo例程(库函数版)发布

    一.说 明: 1.iHMI43 演示程序(0.15版)的库函数版:此程序仅用于 iHMI43 液晶模块: 2.各外设驱动均使用库函数模式操作,其他程序可参考本例子修改: 3.如果下载不进去,请重新配置 ...

  8. ibatis动态sql配置启动时提示:The content of elements must consist of well-formed character data...

    ibatis动态sql配置启动时提示:The content of elements must consist of well-formed character data... 2012-07-18 ...

  9. ThinkPHP中Xheditor编辑器报错

    在使用Xheditor这个插件时..我按照他里面的domo中的方法放到自己的控制器中..出现如下问题 以下是我节选的错误提示 /index.php/admin/goods/upload/ 上传接口发生 ...

  10. VS编程中找不到Microsoft.Office.Core、Microsoft.Office.Interop.Word和VBIDE

    在使用vs2005. vs2008. vs2010 制作包含 word等office的应用程序时,有时找不到对Microsoft.Office.Core. Microsoft.Office.Inter ...