HDU1241:Oil Deposits(DFS)
来源:互联网 发布:支付宝源码 编辑:程序博客网 时间:2024/05/19 03:28
渣渣表示贼鸡儿难,,,,
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32782 Accepted Submission(s): 19045
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<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=120;int n,m,ex,ey,flag;char s[maxn][maxn];int vis[maxn][maxn];void dfs(int x,int y){vis[x][y]=1;for(int i=-1;i<=1;i++){for(int j=-1;j<=1;j++){int xx=x+i,yy=y+j;if(xx>=0&&yy>=0&&xx<n&&yy<m&&vis[xx][yy]==0&&s[xx][yy]=='@')dfs(xx,yy);}}}int main(){while( ~scanf("%d%d",&n,&m),n+m){int ans=0;memset(vis,0,sizeof(vis));for(int i=0;i<n;i++)scanf("%s",s[i]);flag=0;for(int i=0;i<n;i++)for(int j=0;j<m;j++){if(vis[i][j]==0&&s[i][j]=='@'){ans++;dfs(i,j);}}printf("%d\n",ans);}return 0;}
阅读全文
0 0
- Oil Deposits hdu1241 dfs
- HDU1241:Oil Deposits(DFS)
- hdu1241(DFS Oil Deposits )
- HDU1241:Oil Deposits(DFS)
- HDU1241 Oil Deposits DFS
- HDU1241 Oil Deposits DFS
- HDU1241 Oil Deposits 【DFS】
- dfs hdu1241 Oil Deposits
- HDU1241:Oil Deposits(DFS)
- HDU1241 Oil Deposits(dfs)
- HDU1241 Oil Deposits(DFS)
- hdu1241 Oil Deposits(dfs)
- 初学DFS:HDU1241 Oil deposits
- HDU1241 Oil Deposits【dfs&bfs】
- 【DFS&BFS】HDU1241-Oil Deposits
- HDU1241 Oil Deposits(深搜DFS)
- HDU1241 Oil Deposits 解题报告--dfs
- UVA572 HDU1241 POJ1562 Oil Deposits【DFS】
- Android软件开发之PreferenceActivity中的组件
- 关于Python2.7得到结果乱码的问题解决办法
- proxy-target-class之坑
- POJ 3683 2-SAT 输出可行方案
- 求一个只包含0、1的矩阵中只包含1的最大子矩阵大小
- HDU1241:Oil Deposits(DFS)
- 微信自动关闭内置浏览器页面
- 移除DOM节点中的所有属性的正则表达式
- python——反转字典的两种方法(字典的key和value对换)
- 关于vertical-align的一点心得
- 优势+工具+实践=DevOps&Docker的企业级落地
- HDU Find the hotel(RMQ)
- 地形材质总结
- BFS--状态图--uva10603 Fill