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. 【wikioi】1907 方格取数3(最大流+最大权闭合子图)

    http://www.wikioi.com/problem/1907/ 这题我一开始想到的是状压,看到n<=30果断放弃. 然后也想到了黑白染色,然后脑残了,没想到怎么连边. 很简单的一题 黑白 ...

  2. elasticsearch2.2 集群搭建各种坑

        目前生产环境的es版本是1.0版本,需要升级到最新的2.2版本,于是在测试环境进行部署集群测试,在测试过程中遇到的坑相当多,下面详细介绍下.       1. 版本升级到2.2后,必须建一个单 ...

  3. oracle存储过程、声明变量、for循环|转|

    oracle存储过程.声明变量.for循环 1.创建存储过程 create or replace procedure test(var_name_1 in type,var_name_2 out ty ...

  4. 图解classloader加载class的流程及自定义ClassLoader

    图解classloader加载class的流程及自定义ClassLoader 博客分类: JVM JavaJVM虚拟机EXTSUN /** *  转载请注明作者longdick    http://l ...

  5. python 操作mysql

    安装模块: #pip install .... MySQLdb(2.x) pymysql(3.x) import MySQLdb as sql con = sql.connect( host = &q ...

  6. android之listview

    首先建立res/layout/data_list.xml: 代码如下: <?xml version="1.0" encoding="utf-8"?> ...

  7. codeacademy

    codeacademy http://link.zhihu.com/?target=https%3A//www.youtube.com/playlist%3Flist%3DPLP6DbQBkn9ymG ...

  8. 微博开发平台java SDK demo学习之friendships

    本文解释了在java SDK的demo中与feiendships有关的功能 截图如下: 关注一个用户(需要知道该用户uid) 取消关注一个用户(用户uid) 获取用户粉丝列表(授权用户的screen_ ...

  9. 【新产品发布】EVC9001 USB 隔离器

     一. 简介 EVC9001采用Analog Device 公司的基于芯片级变压器的iCoupler 磁耦合隔离方案,完成了对USB接口双向隔离功能,隔离电压达 2500V(隔离电源模块 3000V隔 ...

  10. Scrum会议5(Beta版本)

    组名:天天向上 组长:王森 组员:张政.张金生.林莉.胡丽娜 代码地址:HTTPS:https://git.coding.net/jx8zjs/llk.git SSH:git@git.coding.n ...