Oil Deposits

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 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

are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.

Sample Input

  1. 1 1
  2. *
  3. 3 5
  4. *@*@*
  5. **@**
  6. *@*@*
  7. 1 8
  8. @@****@*
  9. 5 5
  10. ****@
  11. *@@*@
  12. *@**@
  13. @@@*@
  14. @@**@
  15. 0 0

Sample Output

  1. 0
  2. 1
  3. 2
  4. 2
  5.  
  6. 搜索水题。枚举每个起始点,向外扩展与他相邻的点。起始点的个数即为连通块个数。
  1. #include<stdio.h>
  2.  
  3. char a[][];
  4. int c,n,m;
  5. void dfs(int x,int y){
  6. if(x<||y<||x>=n||y>=m) return;
  7. if(a[x][y]=='*') return;
  8. if(a[x][y]=='@'){
  9. a[x][y]='*';
  10. dfs(x+,y);
  11. dfs(x+,y+);
  12. dfs(x,y+);
  13. dfs(x-,y+);
  14. dfs(x-,y);
  15. dfs(x-,y-);
  16. dfs(x,y-);
  17. dfs(x+,y-);
  18. }
  19. }
  20. int main()
  21. {
  22. int i,j;
  23. while(scanf("%d%d",&n,&m)&&!(n==&&m==)){
  24. c=;
  25. for(i=;i<n;i++){
  26. getchar();
  27. scanf("%s",a[i]);
  28. }
  29. for(i=;i<n;i++){
  30. for(j=;j<m;j++){
  31. if(a[i][j]=='@'){
  32. c++;
  33. dfs(i,j);
  34. }
  35. }
  36. }
  37. printf("%d\n",c);
  38. }
  39. return ;
  40. }

HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题的更多相关文章

  1. [POJ] 1562 Oil Deposits (DFS)

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16655   Accepted: 8917 Des ...

  2. POJ 1562 Oil Deposits (并查集 OR DFS求联通块)

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14628   Accepted: 7972 Des ...

  3. (简单) POJ 1562 Oil Deposits,BFS。

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

  4. opencv —— floodFill 漫水填充法 实现证件照换背景

    漫水填充:floodFill 函数 简单来说,漫水填充就是自动选中与种子像素相连的区域,利用指定颜色进行区域颜色填充.Windows 画图工具中的油漆桶功能和 Photoshop 的魔法棒选择工具,都 ...

  5. POJ 1562 Oil Deposits (HDU 1241 ZOJ 1562) DFS

    现在,又可以和她没心没肺的开着玩笑,感觉真好. 思念,是一种后知后觉的痛. 她说,今后做好朋友吧,说这句话的时候都没感觉.. 我想我该恨我自己,肆无忌惮的把她带进我的梦,当成了梦的主角. 梦醒之后总是 ...

  6. POJ 1562 Oil Deposits

    转载请注明出处:http://blog.csdn.net/a1dark 大规模的图论切题之旅正式开始了.由于今天停了一天的电.所以晚上才开始切题.直到昨晚才把图论大概看了一遍.虽然网络流部分还是不怎么 ...

  7. poj 1562 Oil Deposits (广搜,简单)

    题目 简单的题目,只是测试案例的输入后面可能有空格,所以要注意一下输入方式. #define _CRT_SECURE_NO_WARNINGS //题目的案例输入n,m后面有些貌似有空格... #inc ...

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

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

  9. HDU1241 Oil Deposits —— DFS求连通块

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...

随机推荐

  1. php pack()函数详解与示例

    pack和unpack在一般的程序中还真的不容易见到,但是如果你用过很久以前的php生成excel你就会知道了.他的excel的头就是pack出来的最近在尝试与C交互的时候又用上了这玩意,所以不得不再 ...

  2. TXT文本写入数据库

    load data local infile "D:/abc.txt" into table lee; leedabao.txt内容如下,中间用Tab隔开: 2 yuanpeng ...

  3. LeetCode(16)题解--3Sum Closest

    https://leetcode.com/problems/3sum-closest/ 题目: Given an array S of n integers, find three integers ...

  4. bootstrap-table 行内编辑

    1.文件引入 <link rel="stylesheet" href="bootstrap.css"> <link rel="sty ...

  5. 20170319 ABAP 生成XML文件

    方法一:ABAP 使用method方式操作XML 转自:http://www.cnblogs.com/jiangzhengjun/p/4265595.html 方法二:STRANS 转换工具;使用st ...

  6. Remote Debugging Android Devices

    Remote Debugging Android Devices //在电脑上远程调试安卓设备 By Kayce Basques Technical Writer at Google By Meggi ...

  7. java JDBM2 的几个简单实例

    JDBM2 提供了 HashMap 和 TreeMap 的磁盘存储功能,简单易用,用于持久化数据.特别适合用于嵌入到其他应用程序中. 磁盘数据库 HelloWorld.java import java ...

  8. CMTime 与 CMTimeMakeWithSeconds

    1.首先先看代码,这段代码的作用就是要让视频播放区域有个封面.不会显的太空当. - (void)avPlayerDidPlayed:(NSNotification *)noti { [_avPlaye ...

  9. CSS Overflow 属性清除浮动

    清除浮动 设置overflow的一个更流行的用处是,说也奇怪,清除浮动.设置overflow并不会在该元素上清除浮动,它将清除自己(self-clear).意思就是,应用了overflow(auto或 ...

  10. Android系统编译错误Note: Some input files use or override a deprecated API. 解决办法【转】

    本文转载自:http://blog.csdn.net/lilidejing/article/details/46564491 进入系统framework层修改了下MediaPlayer.java的源码 ...