pku 1562 Oil Deposits(典型的BFS)
来源:互联网 发布:菲诗小铺金盏花知乎 编辑:程序博客网 时间:2024/05/14 01:59
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 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
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
这一题是最基本的广搜,只需要在搜到@后把与它相连的@全部变成*,每当搜到一个@,flag就+1,最后输出flag。
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<iostream>
- #include<queue>
- using namespace std;
- int m,n;
- char a[105][105];
- void find(int i,int j)
- {
- int l,k,b,c;
- int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1}};
- a[i][j]='*';
- for(l=0;l<8;l++)
- {
- b=i+dir[l][0];
- c=j+dir[l][1];
- if(b>=0&&c>=0&&b<m&&c<n&&a[b][c]=='@')
- {
- find(b,c);
- }
- }
- }
- int main()
- {
- int i,j,k,l,flag=0;
- scanf("%d",&k);
- for(l=0;l<k;l++)
- {
- flag=0;
- scanf("%d%d",&m,&n);
- 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]=='@')
- {
- flag++;
- find(i,j);
- }
- }
- printf("%d\n",flag);
- }
- return 0;
- }
- pku 1562 Oil Deposits(典型的BFS)
- Oil Deposits pku 1562
- Oil Deposits pku 1562
- pku 1562 Oil Deposits---dfs
- POJ 1562-Oil Deposits(BFS)
- UVA Oil Deposits (BFS)
- Oil Deposits(HD_1241)BFS
- PKU 1562/HDU 1241 Oil Deposits(原油有多少块区域---BFS,DFS)
- Oil Deposits(hdu1241简单的bfs)
- poj 1562Oil Deposits( BFS DFS)
- POJ 1562/HDU 1241 Oil Deposits(BFS)
- UVA 572 Oil Deposits (简单BFS)
- HDU-#1241 Oil Deposits(BFS & DFS)
- UVA-572 Oil Deposits(BFS)
- uva 572 Oil Deposits(bfs实现)
- HDU-1241-Oil Deposits(BFS)
- hd 1241 Oil Deposits (dfs || bfs)
- HDU1241 Oil Deposits(dfs or bfs)
- linux 线程等待队列
- 在超链接中传递中文的乱码问题
- 企业信息化杂汤:信息化和基础信息化(补遗)
- Linux开机启动(bootstrap)
- 关于dijkstra
- pku 1562 Oil Deposits(典型的BFS)
- jquery插件实现qq相册功能
- 【OpenJudge】【数据结构】全题解
- CentOS中vsftp安装与配置
- 对'Consistent Gets',''Physical Reads'和'DB Block Gets'的理解和解释
- 仿优酷评论留言板
- hdu 1076——An Easy Task
- Javascript数据结构操作
- CGI编程学习