暑假集训第三周周六赛 搜索 F - Oil Deposits 油块
2015-08-02 14:54
363 查看
F - Oil Deposits
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice HDU
1241
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
2
分析:
也是根据坐标的的变化去处理各种情况,只不过这个是搜索几次就代表有几个油块,比较好处理一些
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice HDU
1241
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
2
分析:
也是根据坐标的的变化去处理各种情况,只不过这个是搜索几次就代表有几个油块,比较好处理一些
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include<stdio.h> int m,n,s; char a[110][110]; int c[8]= {-1,-1,-1,0,0,1,1,1},b[8]= {-1,0,1,-1,1,-1,0,1}; void DFS(int i,int j) { if(i<0||j<0) return; if(a[i][j]=='@') { a[i][j]='*'; for(int k=0; k<8; k++) DFS(i+c[k],j+b[k]); } } int main() { int i,j; while(scanf("%d %d",&m,&n)&&m+n) { s=0; for(i=0; i<m; i++) scanf("%s",a[i]); for(i=0; i<m; i++) for(j=0; j<n; j++) if(a[i][j]=='@') { s++; DFS(i,j); } printf("%d\n",s); } return 0; }
相关文章推荐
- DFS解数独问题
- hdu1016 Prime Ring Problem 素数环
- hdu1241Oil Deposits 深广搜
- 深搜随想
- UVA 291 The House Of Santa Claus(DFS/深搜)
- POJ 2192 / ZOJ 2401 : Zipper - DP
- POJ3009 Curling 2.0 DFS 深搜
- 小学生玩ACM----深搜
- 杭电 HDU 1426 Sudoku Killer
- NYOJ927The partial sum problem
- NYOJ587blockhouses
- 搜索之“炸弹人”
- hdu1584 深搜水题
- 2012蓝桥杯决赛-数独
- 历届试题 大臣的旅费
- NYOJ--20(搜索)-题目----------------------------- 吝啬的国度
- NYOJ--32(搜索)-题目-----------------------------组合数
- NYOJ--27(搜索)-题目-----------------------------水池数目
- NYOJ--42(搜索)-题目----------------------------- 一笔画问题
- NYOJ--58(搜索)-题目-----------------------------最少步数