搜索算法基础之Oil Deposits
来源:互联网 发布:淘宝卖家衣服轮播图 编辑:程序博客网 时间:2024/06/10 01:32
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22018 Accepted Submission(s): 12710
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这个可以说是搜索中最简单的题之一了 直接深搜 就OK了#include <cstdio>#include <cstring>#include <iostream>using namespace std;int go[8][2] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};int n , m;char map[101][101];void dfs(int x,int y){ int xx,yy; for(int i = 0; i < 8; i++) { xx = x + go[i][0]; yy = y + go[i][1]; if(xx>=0&&xx<n&&yy>=0&&yy<m&&map[xx][yy]!='*') { map[xx][yy] = '*'; dfs(xx,yy); } }}int main(){ while(cin >> n >> m,n||m) { int sum = 0; for(int i = 0; i < n; i++) for(int j = 0; j< m; j++) cin >> map[i][j]; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) { if(map[i][j]=='@') { map[i][j] = '*'; sum++; dfs(i,j); } } cout << sum << endl; } return 0;}题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241
0 0
- 搜索算法基础之Oil Deposits
- Oil Deposits (搜索)
- 【搜索-DFS】Oil Deposits
- 搜索Oil Deposits
- Oil Deposits(基础dfs)
- hdu 1241 Oil Deposits(搜索基础题)
- Oil Deposits 简单搜索 DFS()
- hdu1241 Oil Deposits(搜索)
- 搜索(B - Oil Deposits)
- HDU-Oil Deposits-油田搜索
- HDU1241 Oil Deposits 搜索入门
- POJ 1562 Oil Deposits 搜索
- 搜索—Problem_1011-Oil Deposits
- 搜索dfs-hdu Oil Deposits
- 搜索专题:HDU1241 Oil Deposits
- xynuoj Oil Deposits(搜索)
- Oil Deposits (八个方向搜索)
- uva572--oil deposits--dfs算法
- 汇编语言小知识点
- kindeditor上传图片时候,上传成功了,但是页面上却提示失败
- 美国罗斯福纪念公园墙上刻着的一段总统名言
- android 自动更新APP版本,并使用ProgressDialog显示进度
- 新建target后info.plist的路径关联指向问题
- 搜索算法基础之Oil Deposits
- Android屏幕分辨率的问题,dp,px,density等概念
- android-Selector控件点击效果设置
- printf中几个不常用的格式说明
- 判断ios中是否安装了某些软件
- 双向链表的操作
- Android Fragments 详细使用
- 解决新版本Chrome无法显示border-image问题
- JNI接口函数 (1)