【POJ 1562】 Oil Deposits
来源:互联网 发布:em算法应用实例 编辑:程序博客网 时间:2024/06/02 11:12
Description
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
Sample Output
0
1
2
2
解题思路
本题与POJ 2386思路相同
参考代码
#include <stdio.h>#include <string.h>const int maxn = 110;char oil[maxn][maxn];int r,c;void dfs(int x,int y);int main(){ while (~scanf("%d%d",&r,&c),r){ memset(oil,0,sizeof(oil)); for (int i = 0;i < r;i++) scanf("%s",oil[i]); int ans = 0; for (int i = 0;i < r;i++) for (int j = 0;j < c;j++) if (oil[i][j] == '@'){ dfs(i,j); ans++; } printf("%d\n",ans); } return 0;}void dfs(int x,int y){ oil[x][y] = '*'; for (int dx = -1;dx <= 1;dx++) for (int dy = -1;dy <= 1;dy++){ int nx = x+dx,ny = y+dy; if (0 <= nx && nx < r && 0 <= ny && ny < c && oil[nx][ny] == '@') dfs(nx,ny); }}
- Oil Deposits(POJ 1562)
- poj 1562 Oil Deposits
- POJ 1562 Oil Deposits
- poj 1562 Oil Deposits
- poj 1562 Oil Deposits
- poj-1562Oil Deposits
- POJ-1562-Oil Deposits
- POJ 1562 Oil Deposits
- POJ 1562 Oil Deposits
- POJ 1562 Oil Deposits
- POJ 1562 Oil Deposits
- poj 1562 Oil Deposits
- poj 1562 Oil Deposits
- POJ:1562 Oil Deposits
- poj 1562 Oil Deposits
- poj 1562:Oil Deposits
- poj 1562 oil Deposits
- POJ 1562 Oil Deposits
- 【POJ 2386】 Lake Counting
- poj 1062 最短路(昂贵的聘礼)
- iptables防火墙原理详解
- MVC,MVP 和 MVVM 的图示
- aoj0118结题报告(太简单了,就不说明了)
- 【POJ 1562】 Oil Deposits
- 跨平台编译coocs2d-x工程
- file标签之保存文件
- 数组第二十二课,String类的常用方法
- dfs
- C++拾遗--malloc free与new delete的同与不同
- (五十九)iOS网络基础之UIWebView简易浏览器实现
- ubuntu下一些常用的命令
- 网球之李娜