搜索练习4/hdu.edu.cn/problem1241 /Oil Deposits/基础dfs
来源:互联网 发布:the greedy python 编辑:程序博客网 时间:2024/05/16 05:06
http://acm.hdu.edu.cn/showproblem.php?pid=1241
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 30271 Accepted Submission(s): 17525
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
AC代码:
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<vector>#include<map>#include<string>#define LL long long#define eps 1e-8using namespace std;const int mod = 1e7+7;const int inf = 0x3f3f3f3f;const int maxx = 200100;const int N = 105;char ma[N][N];int v[N][N];int dx[10]={0,0,1,1,1,-1,-1,-1};int dy[10]={1,-1,1,-1,0,1,-1,0};int n,m;void dfs(int a,int b){ if(ma[a][b]=='*') return ; ma[a][b]='*'; for(int i=0;i<8;i++) if(a+dx[i]>=0&&b+dy[i]>=0&&a+dx[i]<n&&b+dy[i]<m) dfs(a+dx[i],b+dy[i]); return ;}int main(){ while(~scanf("%d%d",&n,&m)) { if(n==0&&m==0) break; for(int i=0;i<n;i++) scanf("%s",ma[i]); int ans=0; for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(ma[i][j]=='@') { dfs(i,j); ans++; } printf("%d\n",ans); } return 0;}
0 0
- 搜索练习4/hdu.edu.cn/problem1241 /Oil Deposits/基础dfs
- 搜索dfs-hdu Oil Deposits
- HDU 1241Oil Deposits(dfs搜索)
- 【搜索-DFS】Oil Deposits
- hdu Oil Deposits(DFS)
- Oil Deposits(基础dfs)
- Oil Deposits 简单搜索 DFS()
- HDU/HDOJ 1241 Oil Deposits (DFS)深度优先搜索
- hdu 1241 Oil Deposits (dfs)
- HDU-1241 Oil Deposits (DFS)
- HDU 1241 Oil Deposits (DFS)
- 【DFS】hdu:1241 Oil Deposits
- hdu 1241dfs Oil Deposits
- hdu 1241 Oil Deposits(DFS)
- HDU--1241:Oil Deposits (DFS)
- HDU 1241 Oil Deposits 【DFS】
- HDU 1241 Oil Deposits(dfs)
- HDU 1241 -- Oil Deposits (dfs)
- C# 从网络上获取图片
- 17.04.29 KFC -Z+W
- HDU 2001 计算两点间距离 新手水题
- STL标准库中vector list deque的区别
- PHP设计模式系列(五):原型模式
- 搜索练习4/hdu.edu.cn/problem1241 /Oil Deposits/基础dfs
- cjson添加到Cocos2d-lua项目中
- Hdfs的JAVA客户端基本操作
- Linux apache-activemq安装及配置
- 简书那些事儿
- 每年10万被动收入目标分解 | 进击
- Java锁----Lock实现原理
- Spark RDD、DataFrame和DataSet的区别
- JavaScript学习(二)