uva 572 oil deposits——yhx
Oil Deposits |
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 and
. 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.
#include<cstdio>
#include<cstring>
int xx[]={-,-,-,,,,,},yy[]={-,,,-,,-,,},m,n;
bool map[][];
void dfs(int x,int y)
{
int i,j,k,p,q;
for (i=;i<=;i++)
{
p=x+xx[i];
q=y+yy[i];
if (p>=&&p<=m&&q>=&&q<=n&&map[p][q])
{
map[p][q]=;
dfs(p,q);
}
}
}
int main()
{
int i,j,k,p,q,ans;
char c,s[];
while (scanf("%d%d",&m,&n)&&m&&n)
{
memset(map,,sizeof(map));
gets(s);
for (i=;i<=m;i++)
{
gets(s+);
for (j=;j<=n;j++)
if (s[j]=='@')
map[i][j]=;
}
ans=;
for (i=;i<=m;i++)
for (j=;j<=n;j++)
if (map[i][j])
{
map[i][j]=;
dfs(i,j);
ans++;
}
printf("%d\n",ans);
}
}
每找到一个点,就将他DFS,标记掉所有周围的点。
uva 572 oil deposits——yhx的更多相关文章
- UVA 572 -- Oil Deposits(DFS求连通块+种子填充算法)
UVA 572 -- Oil Deposits(DFS求连通块) 图也有DFS和BFS遍历,由于DFS更好写,所以一般用DFS寻找连通块. 下述代码用一个二重循环来找到当前格子的相邻8个格子,也可用常 ...
- UVA 572 Oil Deposits油田(DFS求连通块)
UVA 572 DFS(floodfill) 用DFS求连通块 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format: ...
- UVa 572 Oil Deposits(DFS)
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil ...
- UVA - 572 Oil Deposits(dfs)
题意:求连通块个数. 分析:dfs. #include<cstdio> #include<cstring> #include<cstdlib> #include&l ...
- Uva 572 Oil Deposits
思路:可以用DFS求解.遍历这个二维数组,没发现一次未被发现的‘@’,便将其作为起点进行搜索.最后的答案,是这个遍历过程中发现了几次为被发现的‘@’ import java.util.*; publi ...
- UVa 572 - Oil Deposits (简单dfs)
Description GeoSurvComp地质调查公司负责探測地下石油储藏. GeoSurvComp如今在一块矩形区域探測石油.并把这个大区域分成了非常多小块.他们通过专业设备.来分析每一个小块中 ...
- UVa 572 Oil Deposits (Floodfill && DFS)
题意 :输入一个m行n列的字符矩阵,统计字符“@”组成多少个八连块.如果两个字符“@”所在的格子相邻(横竖以及对角方向),就是说它们属于同一个八连块. 分析 :可以考虑种子填充深搜的方法.两重for循 ...
- ACM:油田(Oil Deposits,UVa 572)
/* Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- Oil Deposits UVA - 572
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...
随机推荐
- ToDoList:一款非常优秀的任务管理软件 —— 工具类
ToDoList是一款非常优秀的任务管理软件,用户可以方便地组织和安排计划.这是一个开源的项目,很多细节都考虑到了,推荐大家使用~ ToDoList 帮你把要做的事情列出来,一项一项,类似思维导图. ...
- 【原创】C#通用权限管理-程序安全检查,这些你一定要考虑到位
接触通用权限已经一年,现在使用已经很熟练,分享通用权限管理下面的一些好的开发思想. 安全漏洞对于一个小项目来说,可能不是特别的重视,对于一个大项目来说,这是特别重要需要注意的,特别是在项目开发中的就要 ...
- 狂屌的Windows下的定时任务工具xStarter
xStarter是一款将某些常规计算机操作自动化进行为目的的程序. 它不能为你生成word文件,但是它可以周期性地为你备份文件以保持完整性. 程序的特点有:加强的任务计划工具;在系统事件上执行任务;用 ...
- xshell下载文件到本地/上传文件到服务器
xshell很好用,然后有时候想在windows和linux上传或下载某个文件,其实有个很简单的方法就是rz,sz首先你的Ubuntu需要安装rz.sz(如果没有安装请执行以下命令,安装完的请跳过.其 ...
- 每一个成功的程序员的身后都有一个--------Parse
相信好多同行都用过Parse,而正是因为Parse给我们的开发带来的极大的便利,才有了项目从零开始,到正式上线仅仅用上不到两周的时间,现在Swift还在迅速的发展,很快就会占有大量的市场,现在就就结合 ...
- Orchard源码:Logging
试着用markdown写些东西.貌似博客园支持的还有问题,代码片段显示错位,还得另外上传图片.还是用普通方法写写随笔好了. Logging相对也是比较松耦合的模块,可以随时提取出来用在自己的项目中.其 ...
- 如何rename sqlserver database
Problem Sometimes there is a need to change the name of your database whether this is because the or ...
- Upgrade custom workflow in SharePoint
Experience comes when you give a try or do something, I worked in to many SharePoint development pro ...
- Android项目实战(七):Dialog主题Activity实现自定义对话框效果
想必大家都用过Dialog主题的Activity吧,用它来显示自定义对话框效果绝对是一个非常不错的选择. 即把activity交互界面以Dialog的形式展现出来,Dialog主题的Activity大 ...
- 基础学习day01--JAVA入门和JDK的安装与配置
一.软件是什么 软件按照一定顺序组成的计算机指令和数据集合. 二.什么是软件开发 软件开发是使用计算机的语言制作的软件.如迅雷,Windows系统,Linux,QQ等. 三.DOS常用命令 cd..: ...