博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu Oil Deposits
阅读量:6436 次
发布时间:2019-06-23

本文共 2208 字,大约阅读时间需要 7 分钟。

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 此题是最简单的搜索啦,就不说啦,找到一个没用过的入口一直搜下去,就行啦 代码:
#include
#include
char a[105][105];int map[105][105];int dfs(int i,int j);int n,m,count;int main(){        while(scanf("%d%d",&n,&m)!=EOF&&n&&m)    {        int i,j;        count=0;        memset(map,0,sizeof(map));        for(i=0;i
=0&&a[i-1][j]=='@'&&map[i-1][j]==0){map[i-1][j]=1;dfs(i-1,j);}    if(j-1>=0&&a[i][j-1]=='@'&&map[i][j-1]==0){map[i][j-1]=1;dfs(i,j-1);}    if(i+1
=0&&j+1
=0&&a[i+1][j-1]=='@'&&map[i+1][j-1]==0){map[i+1][j-1]=1;dfs(i+1,j-1);}    if(i-1>=0&&j-1>=0&&a[i-1][j-1]=='@'&&map[i-1][j-1]==0){map[i-1][j-1]=1;dfs(i-1,j-1);}    return 1;}

 

转载于:https://www.cnblogs.com/gantaiyuan/p/3212307.html

你可能感兴趣的文章
实验三
查看>>
Hive的作用
查看>>
sql中的case when
查看>>
vue实现分页
查看>>
572:Oil Deposits
查看>>
Spring学习总结(9)——Spring AOP总结
查看>>
切换控制器的三种手段push modal 切换window的rootViewController
查看>>
Eclipse 快捷键大全
查看>>
大小字节序
查看>>
26.删除排序数组中的重复项
查看>>
关于Spring的IOC和DI
查看>>
自动化Cobbler安装
查看>>
深度解析 TypeConverter & TypeConverterAttribute (二)
查看>>
STP生成树算法
查看>>
nginx常用配置
查看>>
英语考试(最小生成树)
查看>>
JS数组操作
查看>>
设置组件局部样式原理-属性选择器
查看>>
慕课-北京理工大学 机器学习 大学生上网时间 聚类,小白学习
查看>>
实用算法实现-第6篇 线段树
查看>>