hdoj1241Oil Deposits
来源:互联网 发布:网络借贷监管法学 编辑:程序博客网 时间:2024/06/16 08:46
Problem 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
0122
这个题跟poj的2386题几乎就是一摸一样的
代码如下:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,ans,nx,ny;char map[110][110];int used[110][110];void dfs(int x,int y){map[x][y]='*';//这里直接将其现在所在位置替换为'.'。以免下次重复搜索 for(int dx=-1;dx<=1;dx++)for(int dy=-1;dy<=1;dy++){int nx=x+dx,ny=y+dy;if(nx>=0&&nx<n&&ny>=0&&ny<m&&map[nx][ny]=='@'){dfs(nx,ny);}}return ;}int main(){while(scanf("%d%d",&n,&m)!=EOF){if(n==0&&m==0)break; int i,j;memset(used,0,sizeof(used));ans=0;for(i=0;i<n;i++)scanf("%s",map[i]);for(i=0;i<n;i++){for(j=0;j<m;j++){if(map[i][j]=='@'){dfs(i,j);ans++;}}}printf("%d\n",ans);}}
0 0
- hdoj1241Oil Deposits
- hdoj1241Oil Deposits
- HDOJ1241Oil Deposits(DFS)
- poj1562&&hdoj1241Oil Deposits
- hdoj1241Oil Deposits bfs|dfs
- hdoj1241Oil Deposits(DFS)
- hdoj1241Oil Deposits(BFS)
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- poj_1562Oil Deposits
- Oil Deposits
- hdu1241Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- servlet中request等中文乱码问题
- 当前不会命中断点还未为文档加载任何符号 解决方法
- 园圆形图片 ImageLoder 实现
- Spark开发指南
- xlistview 上拉刷新 下拉加载
- hdoj1241Oil Deposits
- 函数指针
- 面试题61:按之字形顺序打印二叉树
- 需求分析方法及包装类
- 关于listview,gridview里面数据显示不全的问题
- 二维码
- HDU 4576(概率DP+滚动数组)
- C#使用Unity框架
- pyqt 修改line Edit的背景颜色