HDU 1241 Oil Deposits(石油储藏)

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

 

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.
GeoSurvComp地质勘测公司勘测底下石油。
GeoSurvComp每次处理一块大型矩形区域,并用一个网格将其划分为若干正方形格子。然后使用传感器分析各个格子是否埋藏石油。
藏有石油的格子则被称为口袋。如果两个口袋相邻,则属于同一片石油。石油可能很大并包含多个口袋。你的任务是测定网格上有多少片石油。

CN

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.
输入文件有若干个网格。
每个网格第一行有m和n,表示行与列,以一个空格分隔。
如果m=0则结束输入。此外1 <= m <= 且 <= n <= 。
随后m行,每行n个字符(不含行尾字符)。每个字符表示一个格子,`*'表示没有石油,`@'表示一个石油袋。

CN

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.
对于每个网格,输出有多少片石油。属于同一片石油的相邻口袋关系为水平,重置,或对角线。每片石油不超过100个口袋。

CN

Sample Input - 输入样例

1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0

Sample Output - 输出样例

0
1
2
2

题解
  水题。
  直接拿FZU 2150前半部分的代码稍微改改就A了,不超过100的条件并没有什么用。
  BFS和DFS应该没区别……都能做。

代码 C++

 #include <cstdio>
#include <cstring>
#include <queue>
#define MX 105
struct Point{
int y, x;
} now, nxt;
char map[MX][MX];
int fx[] = { , , -, , , -, , , , , -, -, , -, -, };
std::queue<Point> q;
int main(){
int m, n, opt, i, j, k;
while (scanf("%d%d ", &m, &n), m + n){
opt = ;
memset(map, '*', sizeof map);
for (i = ; i <= m; ++i) gets(&map[i][]); for (i = ; i <= m; ++i) for (j = ; j <= n; ++j){
if (map[i][j] != '@') continue;
now.y = i; now.x = j;
q.push(now); ++opt; map[now.y][now.x] = '*';
while (!q.empty()){
now = q.front(); q.pop();
for (k = ; k < ; k += ){
nxt.y = now.y + fx[k]; nxt.x = now.x + fx[k + ];
if (map[nxt.y][nxt.x] == '@'){ q.push(nxt); map[nxt.y][nxt.x] = '*'; }
}
}
}
printf("%d\n", opt);
}
return ;
}

HDU 1241 Oil Deposits(石油储藏)的更多相关文章

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

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

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

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

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

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

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

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

  5. hdu 1241:Oil Deposits(DFS)

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

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

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

  7. HDU 1241 Oil Deposits (DFS/BFS)

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

  8. HDOJ/HDU 1241 Oil Deposits(经典DFS)

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

  9. hdu 1241 Oil Deposits (简单搜索)

    题目:   The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...

随机推荐

  1. python 列表推导

    废话不多说,直接上代码 #coding=utf-8 def getitem(index, element): return '%d: %s' % (index, element) def getite ...

  2. Redis性能监控

    参考地址: redis教程:http://www.runoob.com/redis/redis-tutorial.html redis百度百科:https://baike.baidu.com/item ...

  3. 量化交易-外汇交易-MetaTrader5

    量化交易-外汇交易-MetaTrader5 外汇有充足的流动性, 7*24, 交易成本低,多空双向,外加杠杆,无人能控盘,有模拟盘,相当适合做量化交易练习积累经验. 第一,全球最大最公平的市场.外汇市 ...

  4. 【JavaScript 6连载】二、函数(工厂模式)

    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"& ...

  5. git log的常见用法

    git log 使用git log命令,什么参数都没有的话,会以下面的格式输出所有的日志(我当前的git仓库只有三个提交).如果日志特别多的话,在git bash中,按向下键来查看更多,按q键退出查看 ...

  6. Django框架----Object Relational Mapping(ORM)

    Django中的ORM Django项目使用MySQL数据库 1. 在Django项目的settings.py文件中,配置数据库连接信息: DATABASES = { "default&qu ...

  7. linux系统Centos环境下搭建SVN服务器及权限配置

    linux系统Centos环境下如何搭建SVN服务器以及svnserve.conf.authz.passwd配置文件详细介绍   至于svn的概念,这里就不做详细阐述了,可以自行百度.简单来讲就是一个 ...

  8. USB开发库STSW-STM32121文件分析(转)

    源: USB开发库STSW-STM32121文件分析

  9. STM32L476应用开发之六:电池SOC检测(转)

    源: STM32L476应用开发之六:电池SOC检测

  10. PyCharm 安装及破解方法

    PyCharm 安装及破解方法 一.安装 首先要下载Pycharm这个软件,可以在官网下载进行下载. 下载完软件之后,双击安装文件即可进行安装,双击后出现下图所示的提示,点击Next即可. 然后会出现 ...