Oil Deposits(DFS深搜)
来源:互联网 发布:绿色傲剑金蛇数据 编辑:程序博客网 时间:2024/05/20 16:09
Link:https://vjudge.net/contest/174968#problem/C
题目:
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
题意:
‘@’为油矿,平行、垂直、对角线上的为同种输出共有多少种
Code:
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<stack>#include<queue>using namespace std;char s[120][120];int dir[][2]={{1,0},{1,1},{1,-1},{-1,1},{-1,-1},{-1,0},{0,1},{0,-1}}; //上、下、左、右、左上、左下、右上、右下八个方向int i,j,m,n;void DFS(int a,int b){ int ax,ay,k; s[a][b]='*'; for(k=0;k<8;k++) { ax=a+dir[k][0]; ay=b+dir[k][1]; if(ax>=0&&ax<m&&ay>=0&&ay<n) { if(s[ax][ay]=='@') DFS(ax,ay); } }}int main(){ int ans; while(~scanf("%d%d",&m,&n)&&m) { for(i=0;i<m;i++) scanf("%s",s[i]); ans=0; for(i=0;i<m;i++) for(j=0;j<n;j++) { if(s[i][j]=='@') { ans++; DFS(i,j); } } printf("%d\n",ans); }return 0;}
阅读全文
1 0
- Oil Deposits(DFS深搜)
- Oil Deposits(dfs深搜)
- Oil Deposits(DFS)
- Oil Deposits (DFS)
- HDU 1241 Oil Deposits(深搜/DFS)
- HDU 1241 Oil Deposits 深搜(DFS)
- poj1562 Oil Deposits(深搜dfs)
- HDU1241 Oil Deposits(深搜DFS)
- poj1562--Oil Deposits(DFS)
- HDU1241 Oil Deposits(DFS)
- hdu1241 Oil Deposits(dfs)
- Oil Deposits(dfs)HDU
- Oil Deposits(dfs水题)
- (DFS)Oil Deposits--HDOJ
- Oil Deposits (深搜)
- hdoj problem 1241 Oil Deposits(深搜 DFS)
- UVA572(Oil Deposits)(DFS)
- Oil Deposits(DFS,基础题)
- cms 系统下应用对象层接口访问MDM
- javascript Window及document对象详细整理
- 剑指offer在线编程(四)
- qt_1_开篇言
- 类和对象
- Oil Deposits(DFS深搜)
- JVM内存区
- 可变参数和泛型--->堆污染
- 操作系统之进程与线程3——内核级线程及切换(未完成)
- Balala Power! HDU
- 3.numpy基础使用
- 求最大公约数-辗转相除法-更相减损术
- Java对象的内存分配过程
- 17暑假多校联赛1.11 HDU 6043 KazaQ's Socks