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. 关于PLC

    学电气的一方面是单片机,一方面是PLC,,,,常常看到说选择比努力更重要,,单片机都很熟悉了,我就来介绍一下PLC..... 然后呢我先吹吹牛,,,目的是让大家相信我介绍的PLC绝对是亲身体验.... ...

  2. bzoj 2726: [SDOI2012]任务安排

    Description 机 器上有N个需要处理的任务,它们构成了一个序列.这些任务被标号为1到N,因此序列的排列为1,2,3...N.这N个任务被分成若干批,每批包含相邻的 若干任务.从时刻0开始,这 ...

  3. locate 命令详解

    locate :http://www.cnblogs.com/peida/archive/2012/11/12/2765750.html 作用:locate命令可以在搜寻数据库时快速找到档案,数据库由 ...

  4. Java NIO (二) 缓冲区(Buffer)

    缓冲区(Buffer):一个用于特定基本数据类型的容器,由 java.nio 包定义的,所有缓冲区都是 Buffer 抽象类的子类. Java NIO 中的Buffer 主要用于和NIO中的通道(Ch ...

  5. JavaBean转Map方法

    Map<String, Object> fieldMap =new HashMap<String, Object>(); BeanInfo beanInfo = Introsp ...

  6. Oracle 启动参数

    查看数据库的SID DB_NAME SERVICE_NAME

  7. Webservice接口的调用

    一.开发webservice接口的方式 1.jdk开发. 2.使用第三方工具开发,如cxf.shiro等等. 我这边介绍jdk方式webservice接口调用. 二.使用jdk调用webservice ...

  8. C# DataGridView 列的显示顺序

    this.dataGridView1.Columns["列名"].DisplayIndex=Convert.ToInt32("你要放置的位置")

  9. spring boot 之fastJson的使用(二)

    昨天说了springboot的简单入门程序.今天进一步深入.今天说一下,fastJson的使用.做过springmvc的都知道fastjson.其实boot自带json可是本人用惯了fastjson, ...

  10. 利用Service Fabric承载eShop On Containers

    从模块化到微服务化 从Pet Shop 到eShop on Container都是Microsoft在技术演进的路径上给开发者展示.Net的开发能力和架构能力的Sample工程,Petshop的时候更 ...