G - Oil Deposits

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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 <string.h>
using namespace std; char map[][];
int way[][];
int all;
int m,n; void read_map()
{
memset(way,,sizeof(way));
for (int i=;i<=m;i++)
{
for (int j=;j<=n;j++)
{
cin>>map[i][j];
}
} } void dfs(int x,int y)
{
way[x][y]=;
if (x+<=m&&map[x+][y]=='@'&&way[x+][y]==) dfs(x+,y);
if (x+<=m&&y->=&&map[x+][y-]=='@'&&way[x+][y-]==) dfs(x+,y-);
if (y->=&&map[x][y-]=='@'&&way[x][y-]==) dfs(x,y-);
if (y->=&&x->=&&map[x-][y-]=='@'&&way[x-][y-]==) dfs(x-,y-);
if (x->=&&map[x-][y]=='@'&&way[x-][y]==) dfs(x-,y);
if (x->=&&y+<=n&&map[x-][y+]=='@'&&way[x-][y+]==) dfs(x-,y+);
if (y+<=n&&map[x][y+]=='@'&&way[x][y+]==) dfs(x,y+);
if (y+<=n&&x+<=m&&map[x+][y+]=='@'&&way[x+][y+]==) dfs(x+,y+);
} int main()
{ while (cin>>m>>n)
{
if (m==&&n==) break; all=;
read_map();
for (int i=;i<=m;i++)
{
for (int j=;j<=n;j++)
{
if (map[i][j]=='@'&&way[i][j]==)
{
dfs(i,j);
all++;
}
}
}
cout<<all<<endl;
} return ;
}

G - Oil Deposits(dfs)的更多相关文章

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

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

  2. Oil Deposits(dfs)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  3. 2016HUAS暑假集训训练题 G - Oil Deposits

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

  4. HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)

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

  5. UVa572 Oil Deposits DFS求连通块

      技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...

  6. HDU 1241 Oil Deposits (DFS/BFS)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. HDU-1241 Oil Deposits (DFS)

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

  8. HDU_1241 Oil Deposits(DFS深搜)

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

  9. UVa 572 Oil Deposits(DFS)

     Oil Deposits  The GeoSurvComp geologic survey company is responsible for detecting underground oil ...

随机推荐

  1. Zigbee事件

    ZIGBEE事件有两类.系统定义事件和用户定义事件. 系统类事件是协议栈已定义好的.用户类事件是我们用户层面来定义的. 事件类号採用一个16bit的常量,使用独热码编码,独热码是仅仅有一个bit为1, ...

  2. ant-design 实现 搜索功能

    1.逻辑代码 list.js /** * 用户列表页 */ import React,{ PureComponent } from 'react' import {connect} from 'rea ...

  3. HTML 5 中WebStorage实现数据本地存储

    webstorage 分sessionStorage和localstorage,sessionStorage是暂时保存,localStorage是永久保存. sessionStorage假设浏览器关闭 ...

  4. 获取取并下载tuku的漫画的爬虫

    代码地址如下:http://www.demodashi.com/demo/12842.html 概述 一个简单的爬虫,实现是爬取tuku网站的漫画.并下载到脚本的文件夹中,下载的漫画按照章节名放在各自 ...

  5. ssl中间证书

    中间证书,其实也叫中间CA(中间证书颁发机构,Intermediate certificate authority, Intermedia CA),对应的是根证书颁发机构(Root certifica ...

  6. atitit.复合变量,也就是类似$$a的变量的原理与实现 java c#.net php js

    atitit.复合变量,也就是类似$$a的变量的原理与实现 java c#.net php js 1.1. 复合变量,也就是类似$$a的变量,它会进行两次的解释. 1 1.2. 数据库里面的复合变量1 ...

  7. OA项目之权限设计②

    1.接着昨天的今天到了设计怎样成功的实现权限分配的功能,首先我们看下这些功能的过程例如以下图: 首先是从user的list页面看到设置权限的button,点击进去进入设置权限的页面 进入设置权限页面, ...

  8. 实时竞价(RTB) 介绍(基础篇)

    前言: 说到"实时竞价"大家一定都不陌生,那么为何如今实时竞价发展这么迅猛,当然这个主要得益于总体移动互联网环境的成熟,以及中国本地移动广告市场出现爆发式增长.那么到底什么是实时竞 ...

  9. Spring 读取配置文件(二)

    Spring 读取配置文件并调用 bean package cn.com.test.receive; import org.springframework.beans.factory.annotati ...

  10. strex,ldrex

    volatile bool lock = false; void func(void) { int i; while(lock);   lock = true; for(i = 0; i < 4 ...