题目描述:

原题:https://vjudge.net/problem/UVA-572

题目思路:

1.图的DFS遍历

2.二重循环找到相邻的八个格子

AC代码:

 #include <iostream>
#include <cstring>
using namespace std; const int maxn = ;
char pic[maxn][maxn] ;
int tag[maxn][maxn] ; //已经遍历过的标志
int m, n; void dfs(int r,int c,int cnt)
{
if(r < || r >= m || c < || c >= n) return ;//排除出界的格子
if(tag[r][c] > || pic[r][c] != '@') return ; //已遍历过或不是@
tag[r][c] = cnt ; //标记
for(int i = -;i <= ;i ++)
for(int j = -;j <= ;j ++)
if(i != || j != ) dfs(r+i,c+j,cnt);
}
int main(int argc, char *argv[])
{
while(scanf("%d%d",&m,&n) == && m && n)
{
for(int i = ;i < m; i++) scanf("%s",pic[i]) ;
memset(tag,,sizeof(tag)) ;
int cnt = ; //连通块个数
for(int i = ;i < m; i++)
for(int j = ;j < n;j++)
if(tag[i][j] == && pic[i][j] == '@') dfs(i,j,++cnt) ;
cout << cnt << endl;
}
return ;
}

油田 (Oil Deposits UVA - 572)的更多相关文章

  1. ACM:油田(Oil Deposits,UVa 572)

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

  2. Oil Deposits UVA - 572

    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...

  3. 【紫书】Oil Deposits UVA - 572 dfs求联通块

    题意:给你一个地图,求联通块的数量. 题解: for(所有还未标记的‘@’点) 边dfs边在vis数组标记id,直到不能继续dfs. 输出id及可: ac代码: #define _CRT_SECURE ...

  4. [C++]油田(Oil Deposits)-用DFS求连通块

    [本博文非博主原创,均摘自:刘汝佳<算法竞赛入门经典>(第2版) 6.4 图] [程序代码根据书中思路,非独立实现] 例题6-12 油田(Oil Deposits,UVa572) 输入一个 ...

  5. 油田 Oil Deposits

    油田 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/L 题意: 输入一个m行n列的字符矩形,统计字符 ...

  6. 洛谷 题解 UVA572 【油田 Oil Deposits】

    这是我在洛谷上的第一篇题解!!!!!!!! 这个其实很简单的 我是一只卡在了结束条件这里所以一直听取WA声一片,详细解释代码里见 #include<iostream> #include&l ...

  7. UVA 572 Oil Deposits油田(DFS求连通块)

    UVA 572     DFS(floodfill)  用DFS求连通块 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format: ...

  8. UVA 572 -- Oil Deposits(DFS求连通块+种子填充算法)

    UVA 572 -- Oil Deposits(DFS求连通块) 图也有DFS和BFS遍历,由于DFS更好写,所以一般用DFS寻找连通块. 下述代码用一个二重循环来找到当前格子的相邻8个格子,也可用常 ...

  9. uva 572 oil deposits——yhx

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

随机推荐

  1. 【Node.js】Jade视图模板的使用

    跟MVC里面的Rezor做差不多的事儿,但是比Rezor弱了一些,比较不喜欢CoffeeScript.Jade这种靠缩进来维系层级结构的做法,就好比接受不了c#中if下面只有一句很长的代码,但是却不加 ...

  2. ARM Cortex-A53 Cache与内存的映射关系以及Cache的一致性分析

    ARM Cortex-A53 Cache与内存的映射关系以及Cache的一致性分析 题记:如果文章有理解不对的地方,欢迎大家批评指正,谢谢大家. 摘要:本文以Cortex-A53为例,首先分析Cach ...

  3. 画布与SVG区别

  4. uva_11806_Cheerleaders

    In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...

  5. linux系统基础之-----磁盘结构(基于centos7.4 1708)

  6. Java OOP——第六章 框架集合

    1.集合框架包含的主要内容及彼此之间的关系: 图1:   集合框架:是为了表示和操作集合而统一规定的一种统一的标准体系结构.               包含三大块的内容:对外的接口.接口的是实现和对 ...

  7. HTML+css3 图片放大效果

    <div class="enlarge"> <img src="xx" alt="图片"/> </div> ...

  8. Vue解决接口访问跨域问题

    随手摘录 Vue解决接口访问跨域问题 1.打开 config -> index.js 2. 找到proxyTable 3.粘贴 如下代码,'https://www.baidu.com'换成要访问 ...

  9. JS 原型总结

    参考: (从内存角度)简单类型与复杂类型及原型链

  10. 小程序开发-11-Promise正确用法与函数签名设计技巧

    配置taBar "tabBar": { "selectedColor": "#000000", "backgroundColor& ...