Oil Deposits(杭电oj1241)(BFS)
来源:互联网 发布:政务软件源码 编辑:程序博客网 时间:2024/05/13 07:21
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13013 Accepted Submission(s): 7540
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
Source
Mid-Central USA 1997
//类似于南阳oj水池数目,这道题是8个方向。
#include<stdio.h>char s[105][105];int a[8]={0,0,1,1,1,-1,-1,-1};int b[8]={1,-1,0,-1,1,-1,1,0};int m,n;void bfs(int x,int y){ int k,v,t;s[x][y]='*';for(k=0;k<8;k++){v=x+a[k]; t=y+b[k];if(s[v][t]=='@'&&v>=1&&v<=m&&t>=0&&t<n){ bfs(v,t); }}}int main(){int i,j,sum;while(scanf("%d%d",&m,&n)&&(m+n)){for(i=1;i<=m;i++){scanf("%s",s[i]);//注意不能用两个for循环,那样也会将空格存入数组。 }for(i=1,sum=0;i<=m;i++){for(j=0;j<n;j++)//j=0是一个需要注意的地方,不是j=1.想想为什么。 if(s[i][j]=='@'){bfs(i,j);sum++;}}printf("%d\n",sum);}return 0;}
0 0
- Oil Deposits(杭电oj1241)(BFS)
- 杭电1241--Oil Deposits(BFS)
- 杭电(hdu)1241 Oil Deposits
- 【杭电1241】Oil Deposits(DFS)
- UVA Oil Deposits (BFS)
- Oil Deposits(HD_1241)BFS
- 杭电bfs 水题1241 Oil Deposits - 油田 详解 + 分析
- UVA 572 Oil Deposits (简单BFS)
- HDU-#1241 Oil Deposits(BFS & DFS)
- POJ 1562-Oil Deposits(BFS)
- 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)
- Oil Deposits(BFS模板题)
- HDU 1241:Oil Deposits(BFS)
- 【hdu 1241】 Oil Deposits (dfs+bfs)
- 城市天气查询(Java网络、面向对象、多线程、IO)
- Sicily 2015 A New Year Gift
- U盘装机
- 【菜鸟学Qt 2】QtCreator仿 VS2013 黑色主题
- 窥视python大门第一眼
- Oil Deposits(杭电oj1241)(BFS)
- unity之综合题总结
- 黑马程序员————java基础---------IO字符流及综合练习题
- 数据库,归档,反归档 修改删除文件夹
- 开源软件库汇总
- 最近在看socket连接,学习了一点适合新手学习,socket客户端和服务端长连接,废话就不多说了,大家看了就明白了
- 为linux kernel 3.17.3 安装的vmwareWrokstation 10.0.4 打补丁
- 刚毕业的程序猿尽量不要去大公司
- leetcode maximum-product-subarray