HDU1241 Oil Deposits(深搜DFS)
来源:互联网 发布:js 输入结束事件 编辑:程序博客网 时间:2024/06/05 09:31
题目:
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 26355 Accepted Submission(s): 15179
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
思路:这道题跟NYOJ上的水池数目非常像,就不写注释了,深搜水题
代码:#include <stdio.h>#include <string.h>int m,n,sum;char map[102][102];int go[8][2] = {{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};void dfs(int i,int j){ int k; map[i][j]='*'; for(k=0; k<8; k++) { if(map[i+go[k][0]][j+go[k][1]]=='@'&&i+go[k][0]>=0&&i+go[k][0]<m&&j+go[k][1]>=0&&j+go[k][1]<n) { dfs(i+go[k][0],j+go[k][1]); } } return;}int main(){ while(1) { sum=0; memset(map,'\0',sizeof(map)); scanf("%d%d",&m,&n); if(m==0)return 0; // getchar(); for(int i=0; i<m; i++) scanf("%s",&map[i]); for(int i=0; i<m; i++) { for(int j=0; j<n; j++) { if(map[i][j]=='@') { sum++; dfs(i,j); } } } printf("%d\n",sum); } return 0;}
0 0
- HDU1241 Oil Deposits(深搜DFS)
- 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 (深搜)
- HDU1241 Oil Deposits 解题报告--dfs
- 14 andriod 多渠道打包,多环境打包 方法
- 小demo
- 第十四周-OJ-C进制转换(数组法)
- 持续集成篇 --Hudson持续集成服务器的安装配置与使用
- 自定义带删除按钮的EditText(输入文字后,最右边浮现×号)
- HDU1241 Oil Deposits(深搜DFS)
- maxLines android:ellipsize="end" Spannable 互相之间存在冲突
- 使Eclipse下支持编写HTML/JS/CSS/JSP页面的自动提示
- PAT(A) 1100
- isDebugEnabled 、isInfoEnabled 为啥要使用
- React Native和hybrid
- Scala继承知识点
- 一个manifest文件格式
- springmvc+jquery 实现ajax页面无刷新请求