Oil Deposits hd 1241
来源:互联网 发布:天津专业seo公司 编辑:程序博客网 时间:2024/05/17 03:55
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
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
#include<cstdio>#include<cstring>#include<iostream>using namespace std;char a[110][110];int n,m,ans;int nx[4]={-1,1,0,0};int ny[4]={0,0,-1,1};void dfs(int r,int c){if(r<0||r>=m||c<0||c>=n||a[r][c]!='@')return;else{a[r][c] = '!'; for(int d=0;d<4;d++)for(int f=0;f<4;f++)dfs(r+nx[d],c+ny[f]);}}int main(){int i,j;while(cin>>m>>n)<span style="white-space:pre"></span>//不能用scanf输入{ if(m==0 || n==0) break; ans=0;for(i=0;i<m;i++){for(j=0;j<n;j++){cin>>a[i][j];}}for(i=0;i<m;i++){for(j=0;j<n;j++){if(a[i][j]=='@'){dfs(i,j);ans++;}}}cout<<ans<<endl; }return 0; }
0 0
- 【HD 1241】Oil Deposits
- Oil Deposits hd 1241
- hd 1241 Oil Deposits (dfs || bfs)
- 1411272217-hd-Oil Deposits
- HDU 1241Oil Deposits
- HDU---1241Oil Deposits
- hdoj 1241 Oil Deposits
- hdoj 1241 Oil Deposits
- Hdu 1241 Oil Deposits
- Hdu 1241 - Oil Deposits
- HDOJ 1241 Oil deposits
- HDU-1241:Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- hdu - 1241 - Oil Deposits
- HDU-1241Oil Deposits
- hdu 1241 Oil Deposits
- 安卓手把手教你实现集成支付宝支付功能
- 超强PCB布线设计经验谈附原理图
- JavaScript 清空、重置 form 表单
- Avoid The Lakes(DFS)
- JS+DIV 实现拖动效果
- Oil Deposits hd 1241
- Final关键字
- 一种可展开伸缩的tableView实现
- MySQL ERROR 1451 (23000) 外键异常处理
- android NDK下log的使用和封装
- sphinx 根据字段在字段内搜索
- PHP用curl模拟登陆并采集后台数据
- HDU Problem 2553 N皇后问题 【DFS】
- [正则表达式]-基础语法二 元字符之限定符与贪婪模式