hdu 1241 Oil Deposits
来源:互联网 发布:刘涛二手衣店淘宝网址 编辑:程序博客网 时间:2024/06/06 15:44
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22551 Accepted Submission(s): 12985
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
#include<iostream>using namespace std;char mapp[65][65];int m,n;void dfs(int x,int y){ if(mapp[x][y]=='*'||x<0||y<0||x>=m||y>=n){ return ; } mapp[x][y]='*'; dfs(x+1,y); dfs(x-1,y); dfs(x,y+1); dfs(x,y-1); dfs(x+1,y+1); dfs(x+1,y-1); dfs(x-1,y+1); dfs(x-1,y-1);}int main(){ int i,j,k; while(cin>>m>>n){ if(m==0&&n==0){ break; } for(i=0;i<m;i++){ for(j=0;j<n;j++){ cin>>mapp[i][j]; } } k=0; for(i=0;i<m;i++){ for(j=0;j<n;j++){ if(mapp[i][j]=='@'){ dfs(i,j); k++; } } } cout<<k<<endl; } return 0;}
0 0
- HDU 1241Oil Deposits
- HDU---1241Oil Deposits
- Hdu 1241 Oil Deposits
- Hdu 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
- hdu 1241 Oil Deposits
- HDU 1241 Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- HDU 1241 Oil Deposits
- hdu-1241-Oil Deposits
- hdu 1241 Oil Deposits
- Codeforces--237C--Primes on Interval(二分水题)
- 局域网 广域网 城域网
- 说说写好的PHP代码如何在wampserver上怎么运行
- UVA 11997 - K Smallest Sums(多路归并)
- sizeof和strlen
- hdu 1241 Oil Deposits
- 归并排序
- KTU Programming Camp (Day 2) Problem F. Sequence of words 后缀数组+线段树
- 阿里云服务器Ubuntu12.04_64bit+php5+MySQL部署过程详解
- 经典导航栏按钮代码
- Qt 错误 The program has unexpectedly finished
- 在Mac中设置Ctrl+C/V进行复制/粘贴
- Java ArrayList 内部源码实现
- 记录使用GitHub经历