题目描述:

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 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

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 <stdio.h>
#include <string.h> using namespace std;
char a[][];
int n,m,i,j; void dfs(int x,int y)
{
a[x][y]='*';
for(int dx=-;dx<=;dx++) //以一个点为中心,判断他周围有无‘@’,一直搜索下去,直到没有相连通的‘@’
for(int dy=-;dy<=;dy++){
int nx=dx+x;
int ny=dy+y;
if(nx>=&&nx<n&&ny>=&&ny<m&&a[nx][ny]=='@') dfs(nx,ny);
}
return ;
} void solve()
{
int ans=;
for(i=;i<n;i++)
for(j=;j<m;j++){
if(a[i][j]=='@')
{
dfs(i,j);
ans++; //每遇到一个‘@’,就将连通快总数加1,并通过dfs把相连通的‘@’都转化成‘*’
}
}
printf("%d\n",ans);
} int main()
{
while(){
scanf("%d%d",&n,&m);
if(n==&&m==) break;
memset(a,,sizeof(a));
for(i=;i<n;i++){
scanf("%s",a[i]); //输入的时候要注意,如果输入%c,记得加getchar();
}
solve();
}
return ;
}

poj1562 Oil Deposits 深搜模板题的更多相关文章

  1. poj1562 Oil Deposits(DFS)

    题目链接 http://poj.org/problem?id=1562 题意 输入一个m行n列的棋盘,棋盘上每个位置为'*'或者'@',求'@'的连通块有几个(连通为8连通,即上下左右,两条对角线). ...

  2. nyoj20——有向无环图深搜模板

    吝啬的国度 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市, ...

  3. uva12558 Egyptian Fractions (HARD version)(迭代深搜)

    Egyptian Fractions (HARD version) 题解:迭代深搜模板题,因为最小个数,以此为乐观估价函数来迭代深搜,就可以了. #include<cstdio> #inc ...

  4. POJ 1562:Oil Deposits

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14462   Accepted: 7875 Des ...

  5. [vijos1159&洛谷1494]岳麓山上打水<迭代深搜>

    题目链接:https://vijos.org/p/1159 https://www.luogu.org/problem/show?pid=1494 这是今天的第三道迭代深搜的题,虽然都是迭代深搜的模板 ...

  6. NYoj 素数环(深搜入门)

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=488 深搜模板: void dfs(int 当前状态) { if(当前状态为边界状 ...

  7. (深搜)Oil Deposits -- hdu -- 1241

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  8. HDU_1241 Oil Deposits(DFS深搜)

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

  9. 暑假集训(1)第七弹 -----Oil Deposits(Poj1562)

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

随机推荐

  1. LINQ to SQL 中 Concat、Union、Intersect、Except 方法的使用

    Ø  前言 LINQ to SQL 中需要对两个或多个数据集进行操作,比如:合并.取交集等,主要使用下面四个方法,这四个方法都是 System.Linq.IQueryable<out T> ...

  2. Docker 容器文件导出 - 六

    Docker 容器 导入导出 导入:import 导出:export 打tar包导出容器 nginx1 的文件系统: # docker export nginx1 > nginx1.tar.gz ...

  3. Java EE之Request部分方法使用示例

    Description: ApplicationProjectName:MedicineMs login.jsp[action:login|method:get] to loginServlet Ou ...

  4. vue的Http请求拦截及处理

    /*公共加载遮罩*/ (function($) { $.fn.jqLoading = function(option) { var defaultVal = { backgroudColor : &q ...

  5. xshell操作

    (1)命令ls——列出文件 ls -la 给出当前目录下所有文件的一个长列表,包括以句点开头的“隐藏”文件 ls a* 列出当前目录下以字母a开头的所有文件 ls -l *.doc 给出当前目录下以. ...

  6. hibernate多表操作

    一.表之间的关系 1.一对一 2.一对多 3.多对多 二.表之间关系建表原则 1.一对多:在多的一方创建一个外键,指向一的一方的主键 2.多对多:创建一个中间表,中间表至少有两个字段,分别作为外键指向 ...

  7. 关于vmvawe的光驱,iso镜像,挂载,卸载

    勾选这个使用iso镜像文件,就相当于真实的环境下,将一张光盘插进了光驱里,然后再勾选启动时连接,那么在linux开机后,/dev/cdrom或者/dev/sr0(前者是后者的软连接)就表示这个硬件设备 ...

  8. java多线程面试题小结

    http://www.importnew.com/12773.html http://www.cnblogs.com/fingerboy/p/5352880.html https://blog.csd ...

  9. Android软键盘在清单文件中所有配置含义

    android:windowSoftInputMode 活动的主窗口如何与包含屏幕上的软键盘窗口交互.这个属性的设置将会影响两件事情: 1>     软键盘的状态——是否它是隐藏或显示——当活动 ...

  10. Elasticsearch 5.4.3实战--Java API调用:索引mapping创建

    因为项目开发使用的是Java语言, 项目的开发架构是Spring MVC+ maven的jar包管理,  所以今天重点说说ES 5.4.3 的Java API的源码实战 1. pom.xml文件增加依 ...