G - Oil Deposits

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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,把四周都遍历就行,计算有几块

 #include <iostream>
#include <string.h>
using namespace std; char map[][];
int way[][];
int all;
int m,n; void read_map()
{
memset(way,,sizeof(way));
for (int i=;i<=m;i++)
{
for (int j=;j<=n;j++)
{
cin>>map[i][j];
}
} } void dfs(int x,int y)
{
way[x][y]=;
if (x+<=m&&map[x+][y]=='@'&&way[x+][y]==) dfs(x+,y);
if (x+<=m&&y->=&&map[x+][y-]=='@'&&way[x+][y-]==) dfs(x+,y-);
if (y->=&&map[x][y-]=='@'&&way[x][y-]==) dfs(x,y-);
if (y->=&&x->=&&map[x-][y-]=='@'&&way[x-][y-]==) dfs(x-,y-);
if (x->=&&map[x-][y]=='@'&&way[x-][y]==) dfs(x-,y);
if (x->=&&y+<=n&&map[x-][y+]=='@'&&way[x-][y+]==) dfs(x-,y+);
if (y+<=n&&map[x][y+]=='@'&&way[x][y+]==) dfs(x,y+);
if (y+<=n&&x+<=m&&map[x+][y+]=='@'&&way[x+][y+]==) dfs(x+,y+);
} int main()
{ while (cin>>m>>n)
{
if (m==&&n==) break; all=;
read_map();
for (int i=;i<=m;i++)
{
for (int j=;j<=n;j++)
{
if (map[i][j]=='@'&&way[i][j]==)
{
dfs(i,j);
all++;
}
}
}
cout<<all<<endl;
} return ;
}

G - Oil Deposits(dfs)的更多相关文章

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

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

  2. Oil Deposits(dfs)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  3. 2016HUAS暑假集训训练题 G - Oil Deposits

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  4. HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)

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

  5. UVa572 Oil Deposits DFS求连通块

      技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...

  6. HDU 1241 Oil Deposits (DFS/BFS)

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

  7. HDU-1241 Oil Deposits (DFS)

    Oil Deposits Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  8. HDU_1241 Oil Deposits(DFS深搜)

    Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...

  9. UVa 572 Oil Deposits(DFS)

     Oil Deposits  The GeoSurvComp geologic survey company is responsible for detecting underground oil ...

随机推荐

  1. pip安装mysql报错 ld: library not found for -lssl

    ld: library not found for -lssl clang: error: linker command failed with exit code (use -v to see in ...

  2. Linux下 安装VMware Tools工具

    Linux下需要安装VMware Tools工具 Linux下需要安装VMware Tools工具来实现主机和虚拟机直接文件复制粘贴功能,安装方法如下: ①点击虚拟机VM菜单栏--虚拟机--安装VMw ...

  3. 【BIEE】14_开发流程介绍

    以上是BIEE开发的流程图,通过流程图我们可以看出在BIEE中存在以下主要内容: 仪表盘 仪表盘页 分析 仪表盘提示 主题区域 Catalog RPD 以下是一些文件以及资料库存储路径 资料库存储路径 ...

  4. 网站定时任务IIS配置

    网站中的定时任务一般是必不可少的,具体的实现方法此文不做详细说明,如有需要了解的请留言.本文主要讲述定时任务有关IIS中的设置. 如果一个网站在20分钟内(IIS默认为20分钟)没有客户端访问,服务器 ...

  5. asp.net+mvc+easyui+sqlite 简单用户系统学习之旅(七)—— 添加用户到数据库-obj转json

    这一节讲一下如何添加用户名和密码到已建的sqlite.db数据库中. 当在datagrid的toolbar中输入用户名.密码,然后点击添加按钮时,将该用户加入数据库,并显示出来.datagrid表格里 ...

  6. Cocos2D-X2.2.3学习笔记10(几何图形)

    我们这节来学习几何图形,即怎样使用Cocos2d-x绘制各种图形.已经贝塞尔曲线 我们查看CCNode中有个draw函数,我们须要将绘制的代码所有写在这个函数里面.写在init函数里是画不出线来的, ...

  7. atitit.线程死锁 卡住无反应 的原因in cmd调用的解决方案  v3 q39

    atitit.线程死锁 卡住无反应 的原因in cmd调用的解决方案  v3 q39 1. 问题::线程死锁  卡住无反应1 1.1. 分类:: cmd调用,  net io  , file  io  ...

  8. 批量分发SSH秘钥

    #!/usr/bin/expect # filename: distribute_key.expif [ $argc != 2 ]{ send_user "usage: expect exp ...

  9. Ionic学习笔记1_基本布局

    <body> <!-- 头部 -->                               bar里嵌入子元素:title,button,button-bar和 inpu ...

  10. C++语言基础(5)-this和static关键字

    一.this关键字 this是一个指针,可用其访问成员变量或成员函数 下面是使用this的一个完整示例: #include <iostream> using namespace std; ...