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 题目大意:给出一个行列式,以‘@’为目标看它有几个连通块,输出其结果。
思路:连通块问题其实就是寻找可行解,将行列式全部
#include <iostream>
#include <cstdio>
#include <cstring>
const int maxn=100+5;
char s[maxn][maxn];
int bi_ji[maxn][maxn];
int m,n;
using namespace std;
void dfs(int r,int c,int d)
{
if(r<0||r>=m||c<0||c>=n)
return;
if(bi_ji[r][c]>0||s[r][c]!='@')
return;
bi_ji[r][c]=d;
for(int dr=-1;dr<=1;dr++)
for(int dc=-1;dc<=1;dc++)
if(dr!=0||dc!=0)
dfs(r+dr,c+dc,d);
}
int main()
{
int qu;
while(scanf("%d%d",&m,&n)==2&&m&&n)
{
memset(bi_ji,0,sizeof(bi_ji));
qu=0;
for(int i=0;i<m;i++)
scanf("%s",s[i]);
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if(!bi_ji[i][j]&&s[i][j]=='@')
dfs(i,j,++qu);
printf("%d\n",qu);
}
return 0;
}
 

Program L 暴力求解的更多相关文章

  1. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  2. Program C 暴力求解

    Description   A ring is composed of n (even number) circles as shown in diagram. Put natural numbers ...

  3. Program A - 暴力求解

    Description   Write a program that finds and displays all pairs of 5-digit numbers that between them ...

  4. Program B 暴力求解

    Given a sequence of integers S = {S1,S2,...,Sn}, you should determine what is the value of the maxim ...

  5. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  6. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  7. BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~

    jrMz and angle       Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Other ...

  8. hdu6570Wave (暴力求解)

    Problem Description Avin is studying series. A series is called "wave" if the following co ...

  9. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

随机推荐

  1. phalcon: 过滤(Phalcon\Filter())

    过滤,就是清除不需要的数据,留下想要的数据. 其调用方法如下,一: $filter = new \Phalcon\Filter(); $filter->sanitize("some(o ...

  2. phalcon: 获取参数的方法

    phalcon: 获取参数的方法 一般情况下:GET/POST $this->request->get(参数); $this->request->getPost("参 ...

  3. 2016年GitHub排名前20的Python机器学习开源项目(转)

    当今时代,开源是创新和技术快速发展的核心.本文来自 KDnuggets 的年度盘点,介绍了 2016 年排名前 20 的 Python 机器学习开源项目,在介绍的同时也会做一些有趣的分析以及谈一谈它们 ...

  4. 机器学习与R语言

    此书网上有英文电子版:Machine Learning with R - Second Edition [eBook].pdf(附带源码) 评价本书:入门级的好书,介绍了多种机器学习方法,全部用R相关 ...

  5. MySQL通用优化手册

    转载: MySQL通用优化手册 内容提纲 MySQL的特点: 硬件.系统优化: MySQL 配置优化: SCHEMA设计优化: SQL 优化: 其他优化. MySQL 的特点 首先,需要明确的是.想要 ...

  6. robotframework笔记27

    文档格式 可以使用简单的HTML格式 测试套件 , 测试用例 和 用户关键字 文档和 免费测试套件 元数据 在测试数据,以及当 记录测试 库 . 格式类似于大多数使用的风格 维基百科,它被设计成可以理 ...

  7. mac svn

    开启svn服务:sudo svnserve -d -r /Users/fuyi/svnserver/mycode/

  8. ubuntu下python3安装类库

    ubuntu是默认安装了python2的,所以直接使用 pip install XXX 是默认安装到python2的,安装到python3 的指令是 pip3 install XXXX 或者 pyth ...

  9. vs版本的改变处理

    今天要用VS2010打开VS2013,一直觉得VS2010到VS2012只是界面上扁平化的改变,平台工具集有改变但很大程度上可能向上兼容.在网上搜了一些文章,其中有一篇说到一个观点:        从 ...

  10. 初学java之触发响应事件

    import java.awt.*; import javax.swing.*; import java.awt.event.*; class WindowActionEvent extends JF ...