Oil Deposits

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31745    Accepted Submission(s): 18440

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
0
1
2
2

题意 求连通块 八个方向

最基础 dfs

AC代码

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#define maxn 105
using namespace std;
int fangxiang[][]={{,},{,-},{-,},{,},{-,-},{,},{,-},{-,}}; //八个方向
char visit[maxn][maxn];
char mapn[maxn][maxn];
int n,m;
void dfs(int x,int y)
{
if(x>=&&x<=n&&y>=&&y<=m) //注意边界
{
if(mapn[x][y]=='@') //覆盖掉已经遍历到的点
{
mapn[x][y]='*';
for(int i=; i<; i++)
{
dfs(x+fangxiang[i][],y+fangxiang[i][]);
}
}
}
else
return;
}
int main()
{
int i,j,k;
while(scanf("%d%d",&n,&m)&&n)
{
int sum=;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
cin>>mapn[i][j];
}
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
if(mapn[i][j]=='@')
{
dfs(i,j);
sum++;
}
}
}
printf("%d\n",sum);
}
}

HDU 1241 DFS的更多相关文章

  1. Oil Deposits HDU - 1241 (dfs)

    Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...

  2. HDU 1241 (DFS搜索+染色)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1241 题目大意:求一张地图里的连通块.注意可以斜着连通. 解题思路: 八个方向dfs一遍,一边df ...

  3. HDU - 1241 dfs or bfs [kuangbin带你飞]专题一

    8个方向求联通块,经典问题. AC代码 #include<cstdio> #include<cstring> #include<algorithm> #includ ...

  4. hdu 1241(DFS/BFS)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  5. HDU 1241 Oil Deposits --- 入门DFS

    HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...

  6. hdu 1241 Oil Deposits(DFS求连通块)

    HDU 1241  Oil Deposits L -DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & ...

  7. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  8. DFS(连通块) HDU 1241 Oil Deposits

    题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...

  9. 深搜基础题目 杭电 HDU 1241

    HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...

随机推荐

  1. 【实验手册】使用Visual Studio Code 开发.NET Core应用程序

    .NET Core with Visual Studio Code 目录 概述... 2 先决条件... 2 练习1: 安装和配置.NET Core以及Visual Studio Code 扩展... ...

  2. AVL树的单双旋转操作

    把必须重新平衡的节点称为å.对于二叉树,å的两棵子树的高度最多相差2,这种不平衡可能有四种情况: 对å的左儿子的左子树进行插入节点(左-左) 对å的左儿子的右子树进行插入节点(左-右) 对å的右儿子的 ...

  3. JPA的基本使用

    前提: 创建一个springboot项目 创建一个名为springboottest的MySQL数据库 1 jar包准备 jpa的jar包 mysql驱动的jar包 druid数据库连接池的jar包 l ...

  4. Windows as a Service(4)——使用Intune管理Windows10更新

    这是这个系列的最后一篇文章,我已经花了三篇的篇幅和大家分享有关于Windows as a Serivce的相关内容,链接如下: Windows as a Service(1)-- Windows 10 ...

  5. tp3.2 事务处理

    事务的机制通常被概括为“ACID”原则即原子性(A).稳定性(C).隔离性(I)和持久性(D).  原子性:构成事务的的所有操作必须是一个逻辑单元,要么全部执行,要么全部不执行.  稳定性:数据库在事 ...

  6. golang社区

    a development list for Go Programming Language https://groups.google.com/forum/#!forum/golang-dev a ...

  7. gitlab 远程 定时备份

    =============================================== 2017/11/1_第2次修改                       ccb_warlock 更新 ...

  8. u3d之世界坐标系,屏幕坐标系,视口坐标系,如何获取物体距离摄像机的距离

    世界坐标系就是unity的左手坐标系 屏幕坐标系是Game视图相机拍摄的场景坐标系,左下角(0,0),右上角(Screen.width,Screen.height),单位是像素.Z的位置是以相机的世界 ...

  9. 浏览器中的user-agent的几种模式

    服务器一般会根据访问的浏览器进行识别,针对不同浏览器才用不同的网站样式及结构,也是通过这个信息判断用户使用的平台模式(手机,pc或平板) 识别为手机一般有这几个关键字: "Windows P ...

  10. Nginx: http 跳转 https

    参考:博文 参考:HTTP 状态码解读 Nginx - rewrite 方式 Nginx Server 配置 server { listen ; server_name www.test.com te ...