UVa 572 Oil Deposits (Floodfill && DFS)
题意 :输入一个m行n列的字符矩阵,统计字符“@”组成多少个八连块。如果两个字符“@”所在的格子相邻(横竖以及对角方向),就是说它们属于同一个八连块。
分析 :可以考虑种子填充深搜的方法。两重for循环枚举所有的点,然后只要是@点且还没被染色过则从这个点出发到达相邻的点染成同样的色(这里的颜色可以用不同的数字来表示),然后每一块@的联通块都能通过这种方式求出来,详情可以参考Wiki百科的动画帮助理解=》http://en.widipedia.org/wiki/Floodfill
#include<bits/stdc++.h> using namespace std; ][], row, col, seed[][], ans = ; ][] = { {-,},{,},{,}, {-,}, {,}, {-,-},{,-},{,-} }; bool bound(int Row, int Col) { || Col< || Row>=row || Col>=col) return true; else return false; } ; inline void DFS(int Row, int Col) { if(!G[Row][Col]) return; else{ seed[Row][Col] = SEED; ; i<; i++){ ]; ]; ) DFS(y, x); } } } int main(void) { while(~scanf("%d %d", &row, &col) && (row&&col)){ ; i<; i++){ memset(G[i], false, sizeof(G[i])); memset(seed[i], , sizeof(seed[i])); } SEED = ; ; i<row; i++){ ; j<col; j++){ char temp; scanf(" %c", &temp); if(temp=='*') G[i][j] = false; else G[i][j] = true; } } ; i<row; i++){ ; j<col; j++){ ) {DFS(i, j);SEED++;} } } printf(); } ; }
经验 :在dfs中需要往八个方向进行搜索,之前的做法从多个if=》存到move数组利用for循环实现=》现在有一个更简便的方法=》
; dr<=; dr++) ; dc<=; dc++){ int y = Row + dr; int x = Col + dc; ) DFS(y, x); }
UVa 572 Oil Deposits (Floodfill && DFS)的更多相关文章
- UVA 572 -- Oil Deposits(DFS求连通块+种子填充算法)
UVA 572 -- Oil Deposits(DFS求连通块) 图也有DFS和BFS遍历,由于DFS更好写,所以一般用DFS寻找连通块. 下述代码用一个二重循环来找到当前格子的相邻8个格子,也可用常 ...
- UVA - 572 Oil Deposits(dfs)
题意:求连通块个数. 分析:dfs. #include<cstdio> #include<cstring> #include<cstdlib> #include&l ...
- UVA 572 Oil Deposits油田(DFS求连通块)
UVA 572 DFS(floodfill) 用DFS求连通块 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format: ...
- UVa 572 Oil Deposits(DFS)
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil ...
- uva 572 oil deposits——yhx
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil d ...
- UVa 572 - Oil Deposits (简单dfs)
Description GeoSurvComp地质调查公司负责探測地下石油储藏. GeoSurvComp如今在一块矩形区域探測石油.并把这个大区域分成了非常多小块.他们通过专业设备.来分析每一个小块中 ...
- Uva 572 Oil Deposits
思路:可以用DFS求解.遍历这个二维数组,没发现一次未被发现的‘@’,便将其作为起点进行搜索.最后的答案,是这个遍历过程中发现了几次为被发现的‘@’ import java.util.*; publi ...
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...
- hdu 1241 Oil Deposits(DFS求连通块)
HDU 1241 Oil Deposits L -DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & ...
随机推荐
- vue-cli3.0使用及部分配置详解
1.检测安装 vue-V 2.创建项目命令:(官网) 3.简单的配置信息 这里如果你是第一次用3.0版本的话,是没有前两个的,而只有最后两个,这里是 让你选的,第一个是默认配置,一般选第二个,自己 ...
- navicat连接 mysql报错1251解决方案
转自:https://blog.csdn.net/XDMFC/article/details/80263215 好不容易安装好mysql,但又出现了mysql客户端版本太低的问题.根据参考的这篇博客, ...
- Linux 下面根据端口号 查询 可执行程序的路劲的方法
1. 安装上lsof 的包 2. 使用 lsof 命令查看相关进程 lsof -i: 效果为: 3. 根据/proc 的目录查看可执行目录的文件位置 ll /proc/procid # procid ...
- PostgreSQL数据库表的内部结构
A page within a table contains three kinds of data described as follows: heap tuple(s) – A heap tupl ...
- node.js使用swig模块
1.安装swig npm install swig --save 2.创建app.js文件 /*应用程序入口文件*/ /*加载express模块*/ var express = require('ex ...
- npm工作流 与webpack 分同环境配置
npm:http://www.ruanyifeng.com/blog/2016/10/npm_scripts.html process.env.npm_lifecycle_event process. ...
- case函数,replace函数
(case '字段' when '数据1' then '输出1' when '数据2' then '输出2' when '数据3' then '输出3' else '其他数据输出一致' end) as ...
- java 内部类复习
/** * 内部类详解 * * @author shao * */ public class InnerClass { public static void main(String[] args) { ...
- 机器学习-非线性回归(Logistic Regression)及应用
1. 概率 1.1 定义:概率(Probability):对一件事情发生的可能性的衡量. 1.2 范围:0 <= P <= 1 1.3 计算方法: 1.3.1 根据个人置信 1.3.2 根 ...
- 十、LaTex数学公式初步