题意 :输入一个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)的更多相关文章

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

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

  2. UVA - 572 Oil Deposits(dfs)

    题意:求连通块个数. 分析:dfs. #include<cstdio> #include<cstring> #include<cstdlib> #include&l ...

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

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

  4. UVa 572 Oil Deposits(DFS)

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

  5. uva 572 oil deposits——yhx

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

  6. UVa 572 - Oil Deposits (简单dfs)

    Description GeoSurvComp地质调查公司负责探測地下石油储藏. GeoSurvComp如今在一块矩形区域探測石油.并把这个大区域分成了非常多小块.他们通过专业设备.来分析每一个小块中 ...

  7. Uva 572 Oil Deposits

    思路:可以用DFS求解.遍历这个二维数组,没发现一次未被发现的‘@’,便将其作为起点进行搜索.最后的答案,是这个遍历过程中发现了几次为被发现的‘@’ import java.util.*; publi ...

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

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

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

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

随机推荐

  1. Spring Boot(十七):使用 Spring Boot 上传文件

      上传文件是互联网中常常应用的场景之一,最典型的情况就是上传头像等,今天就带着带着大家做一个 Spring Boot 上传文件的小案例. 1.pom 包配置 我们使用 Spring Boot 版本 ...

  2. Spring Boot常用功能

    1.Spring Boot打war包配置 利用IDEA将SpringBoot的项目打包成war文件

  3. [转帖][Linux]systemd和sysV

    [Linux]systemd和sysV   转自:https://www.cnblogs.com/EasonJim/p/7168216.html 在Debian8中systemd和sysVinit同时 ...

  4. Element el-table-column组件列宽度设置百分比无效

    问题 使用Element table组件时,给列设置百分比宽度无效(width="30%") 解决 用属性min-width="3"代替属性width=&quo ...

  5. CodeForces-520E Pluses everywhere

    题目描述 给出一个长度为 \(n\) 的字符串,给出一个非负整数 \(k\),要求给这个字符串中间添加 \(k\) 个$\(+\)'号,变成一个表 达式,比如"\(1000101\)&quo ...

  6. 利用BFS解决拯救007问题 -- 数据结构

    题目: 7-1 拯救007 (30 分) 在老电影“007之生死关头”(Live and Let Die)中有一个情节,007被毒贩抓到一个鳄鱼池中心的小岛上,他用了一种极为大胆的方法逃脱 —— 直接 ...

  7. python之网络部分

    1.C/S B/S架构 C: client端 B: browse 浏览器 S: server端 C/S架构: 基于客户端与服务端之间的通信 ​ QQ, 游戏,皮皮虾, 快手,抖音. ​ 优点: 个性化 ...

  8. 认识react, 并简单与vue对比

    应用场景: 负责场景下的高性能 重用组件库,组件组合 中文官网:https://reactjs.org.cn/doc/in... 特点: 声明式编码(不需要关心如何实现,只需要关注在哪里做什么) 组件 ...

  9. 9.jQuery之简洁版滑动下拉菜单

    知识点:hover的使用,已经slideToggle的切换效果 <style> * { margin: 0; padding: 0; } li { list-style-type: non ...

  10. cx_Oracle 操作oracle数据库

    cx_Oracle 操作oracle数据库 class MyOracle(): def __init__(self, host_name="ip", port=1521, sid= ...