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. 手把手教你 用 wpf 制作metro ProgressRing (Windows8 等待动画)

    效果图: 还在羡慕metro的ProgressRing吗? wpf 也可以拥有 首先说下思路, 一共6个点围绕一直圆转,所以需要使用rotation动画 并且一直转下去. 那么下面的问题就好解决了. ...

  2. COJ0702 数学(三)

    数学(三) 难度级别:D: 运行时间限制:1800ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 给出两个正整数a,b,求a*b. 输入 输入共两行,每行是一个正整 ...

  3. C#引用Interop.SQLDMO.dll后的注意事项(转)

    C#引用sqldmo.dll的方法 找到 sqldmo.dll这个文件C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll用.N ...

  4. CentoS 下报的 Requires: perl(:MODULE_COMPAT_5.8.8)

    yum error requires: libtcmalloc.so.4 rpm -Uvh http://ceph.com/rpm-cuttlefish/el6/x86_64/ceph-release ...

  5. 记sql语句空格带来的问题

    在做分页的时候,引用了一个分页类.在一条sql语句出发生错误,没查出数据,代码如下 $sql="select * from sw_goods".$page->limit; 正 ...

  6. 使用javascript打开链接的多种方法

    在页面中的链接除了常规的方式以外,如果使用javascript,还有很多种方式,下面是一些使用javascript,打开链接的几种方式: 1.使用window的open方法打开链接,这里可是在制定页面 ...

  7. MS14-082引起的问题

    经常看报道说打了微软的某某补丁出了什么什么问题,但是本人从未亲身经历过,直到MS14-082这个Office补丁的出现,让我也切身体会了一番,有点中奖的感觉. 具体参见: https://suppor ...

  8. Ubuntu中搭建Nginx+PHP环境最简单的方法

    先安装: sudo apt-get install nginx php5-fpm 然后编辑配置文件: sudo gedit /etc/nginx/site-available/default 找到lo ...

  9. mysql IN 比等价的OR写法效率更高

  10. 【IOS笔记】View Programming Guide for iOS -1

    原文:View Programming Guide for iOS View and Window Architecture Views and windows present your applic ...