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. 

InputThe 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. 
OutputFor 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
#include <bits/stdc++.h>
using namespace std;
#define M 102 char map1[M][M];
int vis[M][M];
int m,n,sum;
int dir[8][2] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; void dfs(int x, int y){
for(int i = 0; i < 8; i++)
{
int dx = x + dir[i][0];
int dy = y + dir[i][1];
if(dx >= 0 && dy >= 0 && dx < m && dy < n && map1[dx][dy] == '@' && !vis[dx][dy]){
vis[dx][dy] = 1;
dfs(dx,dy);
}
}
return;
} int main(){
while(cin>>m>>n && m && n){
memset(vis,0,sizeof(vis));
sum = 0;
getchar();
for(int i = 0; i < m; i++)
scanf("%s",map1[i]);
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
if(map1[i][j] == '@' && !vis[i][j]){
sum++;dfs(i,j);
}
cout<<sum<<endl;
}
return 0;
}

Oil Deposits HDU 1241的更多相关文章

  1. Oil Deposits HDU - 1241 (dfs)

    Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...

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

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

  3. kuangbin专题 专题一 简单搜索 Oil Deposits HDU - 1241

    题目链接:https://vjudge.net/problem/HDU-1241 题意:问有几个油田,一个油田由相邻的‘@’,组成. 思路:bfs,dfs都可以,只需要遍历地图,遇到‘@’,跑一遍搜索 ...

  4. HDU 1241 Oil Deposits --- 入门DFS

    HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...

  5. hdu 1241 Oil Deposits(DFS求连通块)

    HDU 1241  Oil Deposits L -DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & ...

  6. HDU 1241 Oil Deposits(石油储藏)

    HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Probl ...

  7. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  8. DFS(连通块) HDU 1241 Oil Deposits

    题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...

  9. hdu 1241:Oil Deposits(DFS)

    Oil Deposits Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

随机推荐

  1. es_5.4.4 reinstall log and upgrade to V6.5.4--APM

      elastic-APM opbeat is deadhttps://blog.csdn.net/chenwenhao0304/article/details/83302942https://www ...

  2. Xcode编辑器之基本使用(一)

    前言. 苹果原生xcode使用介绍文档 1.Xcode IDE概览 说明: 从左到右,依次是“导航窗格(Navigator)->边列(Gutter)->焦点列(Ribbon)->代码 ...

  3. Oracle shrink table

    shrink必须开启行迁移功能. alter table table_name enable row movement ; 在oracle中可以使用alter table table_name shr ...

  4. tensorflow入门笔记(一) tf.app.flags.FLAGS

    tf.app.flags.DEFINE_xxx()就是添加命令行的optional argument(可选参数),而tf.app.flags.FLAGS可以从对应的命令行参数取出参数.举例如下: FL ...

  5. Appium环境配置(一)

    一:环境准备(Windows 7版本 64位系统) 1.jdk1.6.0 (64位) 2.android-sdk 3.appium 4.Node.js:node-v8.11.1 5.Appium-Py ...

  6. WebSocket 的鉴权授权方案

    引子 WebSocket 是个好东西,为我们提供了便捷且实时的通讯能力.然而,对于 WebSocket 客户端的鉴权,协议的 RFC 是这么说的: This protocol doesn’t pres ...

  7. IAM:亚马逊访问权限控制

    IAM的策略.用户->服务器(仓库.业务体) IAM:亚马逊访问权限控制(AWS Identity and Access Management )IAM使您能够安全地控制用户对 AWS 服务和资 ...

  8. git出现warning: LF will be replaced by CRLF的解决方法

    今天ytkah用git上传文件的时候出现了warning: LF will be replaced by CRLF的错误,具体信息如下,这是因为跨平台开发下产生的.由于编辑器的不同或者Windows程 ...

  9. 008-js中的正则表达式

    查看地址:http://www.runoob.com/js/js-regexp.html 一.正则表达式概述 正则表达式(英语:Regular Expression,在代码中常简写为regex.reg ...

  10. 列表选择框:wxSingleChoiceDialog

    wxSingleChoiceDialog(wxWindow* parent, const wxString& message, const wxString& caption, int ...