/* 题目大意:一块区域中分布着油田,连在一起就属于一个油田,求油田个数。* 也就是求一个无向图的连通分支个数,直接dfs8个方向,水过。。。
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;#define MAX 101
#define DIR 8char a[MAX][MAX];
int visited[MAX][MAX];
int dir[][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1},{0, 1}, {1, -1}, {1, 0}, {1, 1}
};void DFS(int x, int y){if( visited[x][y] || a[x][y] == '*' ) return ;visited[x][y] = 1;for(int i = 0; i < DIR; i ++)DFS(x+dir[i][0], y+dir[i][1]);
}int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGEfreopen("test.in", "r", stdin);
#endifint m, n, ans;while( scanf("%d %d", &m, &n), m || n ){ans = 0;memset(a, '*', sizeof(a));memset(visited, 0, sizeof(visited));for(int i = 0; i < m; i ++){getchar();for(int j = 0; j < n; j ++){scanf("%c", &a[i][j]);}}for(int i = 0; i < m; i ++){for(int j = 0; j < n; j ++){if( a[i][j] == '@' && !visited[i][j] ){ans ++;DFS(i, j);}}}printf("%d\n", ans);}return 0;
}

uva_572 - Oil Deposits相关推荐

  1. L - Oil Deposits HDU - 1241

    L - Oil Deposits HDU - 1241 注意写check的时候要先判x,y是不是越界了,不然直接用数组可能RE, 也可能直接WA了 #include<cstdio> #in ...

  2. UVa572 Oil Deposits DFS求连通块

    技巧:遍历8个方向 for(int dr = -1; dr <= 1; dr++)for(int dc = -1; dc <= 1; dc++)if(dr != 0 || dc != 0) ...

  3. HDU-1241 Oil Deposits (DFS)

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

  4. 【POJ - 1562】Oil Deposits (dfs搜索,连通块问题)

    题干: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...

  5. 【HDU - 1241】Oil Deposits (连通块问题 属于求大海中的岛屿个数 类似问题)

    题干: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...

  6. L - Oil Deposits

    题目描述 The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...

  7. NUC1397 Oil Deposits【DFS】

    Oil Deposits 时间限制: 1000ms 内存限制: 65535KB 问题描述 The GeoSurvComp geologic survey company is responsible ...

  8. 百-寒-进-16-油田Oil Deposits

    Oil Deposits 题目描述 GeoSurvComp地质调查公司负择探测地下石油矿床.该公司一次处理一个大的矩形区域,并创建一个网格,将土地划分为许多正方形地块.然后,它分别分析每个地块,使用传 ...

  9. HDU 1241 Oil Deposits

    题目大意是找到独立的油田个数,所谓独立就是跟它相邻的八个方向上都不能再有别的油田.思路就是每遇到一个'@'都要将它周围的所有'@'都给改成'*',用DFS跟BFS都可以,这里是DFS的代码: AC c ...

  10. UVA572 Oil Deposits DFS求解

    小白书上经典DFS题目. 1. 递归实现 // from: https://www.cnblogs.com/huaszjh/p/4686092.html#include <stdio.h> ...

最新文章

  1. 【ES6】变量的解构赋值
  2. ”过程”在敏捷开发中的位置
  3. 网易发布云计算战略,“为解放程序员而来”
  4. JDK8-lambda表达式四种forEach性能对比
  5. 大数据互联网架构阶段 大型电商项目数据库设计时应该注意的点
  6. 使用action framework 实现order change时自动发送邮件
  7. 流量隔离方案 Dpath 护航双十一新零售
  8. 两台设备有三条链路,请问如何添加?
  9. 微信小程序使用代码切换底部导航
  10. 架构师资源汇总 从入门到精通 将近20年的工作经验毫无保留分享
  11. CUDA C编程(二)CUDA编程模型
  12. maven 安装配置 - vscode for java
  13. DFMEA \FTA
  14. BZOJ3039 玉蟾宫(单调栈)
  15. C#冷门系列之Lazy
  16. mac升级vue-cli
  17. 怎么接受对方tp_恋爱关系中怎么和回避型有效沟通
  18. 油猴安装、编写及添加脚本 笔记
  19. 芋道源码 精尽学习指南
  20. 李艾30场直播数据全解析,挖掘直播高转化技巧

热门文章

  1. 团体程序设计天梯赛-练习集L1-039 古风排版
  2. 程序员必会知识点之 Doherty Threshold (Doherty阈值)App和网站的加载数据的时间用户最大忍受时间是多长
  3. 【无标题】留学挂科影响毕业后学历认证吗?
  4. 陪学读书会——《定位》第十六章-产品定位案例:奶球
  5. Notch:一个程序员如何达到身价1.1亿美元?
  6. 【美赛】2023年ICM问题Z:奥运会的未来(思路、代码)
  7. NLP学习笔记-聊天机器人项目准备(三)
  8. unity一打开就黑屏,怎么办?
  9. 如何搞定团队中的野狗、兔子、黄牛?--基于员工画像的领导力法则
  10. 弗洛伊德算法三重循环的最通俗理解