hdoj-1241-Oil Deposits
来源:互联网 发布:突破阶级的途径 知乎 编辑:程序博客网 时间:2024/05/17 07:28
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 file 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
For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
Sample Input
1 1
*
3 5
@@*
@
@@*
1 8
@@**@*
5 5
**@
@@@
@*@
@@@*@
@@**@
0 0
Sample Output
0
1
2
2
最基础的dfs
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int m,n;char s[105][105];int dfs(int x,int y){ if(s[x][y]=='@'&&x>=0&&x<m&&n>=0&&y<n) { s[x][y]='*'; dfs(x,y-1); dfs(x,y+1); dfs(x+1,y); dfs(x-1,y); dfs(x-1,y-1); dfs(x-1,y+1); dfs(x+1,y-1); dfs(x+1,y+1); } return 0;}int main(){ while(scanf("%d%d",&m,&n)!=EOF) { getchar(); if(m==0) break; for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { scanf("%c",&s[i][j]); } getchar(); } int sum=0; /*for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { printf("%c",s[i][j]); } printf("\n"); }*/ for(int i=0;i<m;i++) for(int j=0;j<n;j++) { if(s[i][j]=='@') { dfs(i,j); sum++; } } printf("%d\n",sum); } return 0;}
- hdoj 1241 Oil Deposits
- hdoj 1241 Oil Deposits
- HDOJ 1241 Oil deposits
- HDOJ 1241 Oil Deposits
- HDOJ 1241 Oil Deposits
- HDOJ 1241 Oil Deposits
- hdoj 1241 Oil Deposits
- hdoj 1241 Oil Deposits
- hdoj 1241 Oil Deposits
- hdoj 1241 Oil Deposits
- hdoj-1241-Oil Deposits
- HDOJ-1241 Oil Deposits
- HDOJ - 1241 Oil Deposits
- hdoj-1241【Oil Deposits】
- hdoj 1241 Oil Deposits
- hdoj-1241 Oil Deposits
- HDOJ--1241--Oil Deposits【DFS】
- ACM HDOJ 1241 (Oil Deposits)
- Java float保留两位小数或多位小数
- JavaScript 笔记
- 监听返回键或其他控件的双击事件
- springcloud(第八篇)springcloud feign
- yii2分页的使用及其扩展
- hdoj-1241-Oil Deposits
- 解决vi/vim中粘贴会在行首多很多缩进和空格的问题
- Hibernate增删改查一些方法的区别
- Java线程创建的三种方式
- 点击效果实现的多种方法
- Zookeeper四字命令
- poj-1321-棋盘问题
- Python Tricks(九)—— 递归遍历目录下所有文件
- [bzoj3307]雨天的尾巴