hdu 1241 Oil Deposits
来源:互联网 发布:大陆网络剧 ptt评论 编辑:程序博客网 时间:2024/04/29 22:53
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11301 Accepted Submission(s): 6585
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
Source
Mid-Central USA 1997
Recommend
Eddy | We have carefully selected several similar problems for you: 1010 1242 1240 1181 1372
#include<iostream>#include<string.h>#include<math.h>using namespace std;int direct[8][2]={-1,0,1,0,0,1,0,-1,1,1,-1,1,-1,-1,1,-1};//八个方向char map[105][105];int m,n;int Dx,Dy;int ans;void DFS(int x,int y){ int p,q,k; map[x][y]='*';//一传进来就变‘*’ for(k=0;k<8;k++) { p=x+direct[k][0]; q=y+direct[k][1]; if(p>=0&&q>=0&&p<m&&q<n&&map[p][q]=='@')//p,m对应行,q,n对应列 DFS(p,q);//递归调用后对应变量x,y }}int main(){ int i,j,k; while(cin>>m>>n,n+m) { for(i=0;i<m;i++){ for(j=0;j<n;j++){ cin>>map[i][j]; } } ans=0;//开始有0个矿 /*对每个点都要进行递归搜索*/ for(i=0;i<m;i++){ for(j=0;j<n;j++){ if(map[i][j]=='@'){ ans++;//出现一个 @群 就加1 DFS(i,j);//对每一个点进行递归搜索 } } } cout<<ans<<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
- HDU1698 Just a Hook 【线段树】+【成段更新】+【lazy标记】
- zoj Friendship 并查集
- [001]今天开始制作自己第一款基于Unity的游戏
- 高精度PSR 恒流PFC控制器QX9931
- Hibernate 4.3.5 hql语句实例
- hdu 1241 Oil Deposits
- uva 11478 最短路径问题(负环,差分约束系统)
- 今天的失望和感悟
- 蛋挞
- HCE NFC
- 偶然看见了,就收录下来,作为对自己的励志吧!
- LIB和DLL的区别与使用
- java List转换为字符串并加入分隔符的一些方法总结
- 【非常强大的Android图表引擎 - AChartSDK】