Oil Deposits

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

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
Source
 
Recommend
Eddy
 

Statistic | Submit | Discuss | Note

思路:'@'代表有石油,然后只要上下相邻或者左右相邻,或者对角相邻都算是一块石油,问有几块石油储备。

就是用dfs或者bfs就行了,得用栈或者队列来模拟。我写的是DFS版

不知道为什么在用scanf读入字符数组时,题目的第四组测试数据总是读入回车。。。getchar也不管用。

换cin好了。。。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <conio.h> using namespace std; typedef struct info{
int i,j;
}location; int m,n;
int countt;
char t;
char oilmap[][];
stack<location> s; int calx[]={-,-,-,,,,,};
int caly[]={-,,,-,,-,,}; void exploit(int i,int j){
location temp={i,j};
location now,next;
s.push(temp);
while(!s.empty()){
now=s.top();
s.pop();
oilmap[now.i][now.j]='*';
for(int k=;k<;k++){
next.i=now.i+calx[k];
next.j=now.j+caly[k];
if(next.i>= && next.i<m && next.j>= && next.j<n){
if(oilmap[next.i][next.j]=='@'){
s.push(next);
}
}
}
} } int main()
{
while(~scanf("%d %d",&m,&n)){
getchar();
if(m==) {break;}
for(int i=;i<m;i++){
for(int j=;j<n;j++){
cin>>oilmap[i][j];
}
}
countt=;
for(int i=;i<m;i++){
for(int j=;j<n;j++){
if(oilmap[i][j]=='@'){
exploit(i,j);
countt++;
}
}
}
printf("%d\n",countt);
}
return ;
}

hdu 1241(DFS/BFS)的更多相关文章

  1. Oil Deposits HDU - 1241 (dfs)

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

  2. HDU 4771 (DFS+BFS)

    Problem Description Harry Potter has some precious. For example, his invisible robe, his wand and hi ...

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

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

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

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

  5. hdu 1242 dfs/bfs

    Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is ...

  6. HDU 1241 DFS

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

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

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

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

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

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

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

随机推荐

  1. django之内置Admin

    本篇导航: 配置路由 定制Admin Django内置的Admin是对于model中对应的数据表进行增删改查提供的组件,使用方式有: 依赖APP: django.contrib.auth django ...

  2. 科技论文之Latex公式&amp;符号

    近期在写文章.有好多数学公式的命令都忘记了. 今天索性一起整理下. 1 能够在文章的作者上引用的符号 2  一些括号使用方法 3 一些高等数学的公式 4  交,并集 5  一些二项式 6 矩阵写法 7 ...

  3. 使用rsync

    rsync是linux下同步文件的一个高效算法,用于同步更新两处计算机的文件和目录,并适当利用查找文件中的不同块以减少数据传输.rsync的主要特点就是增量传输,只对变更的部分进行传送. 增量同步算法 ...

  4. CentOS 6.5 x64下网络配置

    一.自动获取IP地址 #dhclient 自动获取ip地址命令 #ifconfig 查询系统里网卡信息,ip地址.MAC地址 [root@CentOS6 ~]# vi /etc/sysconfig/n ...

  5. Linksys WRT610n V2 刷ddwrt后安装entware-ng,使用opkg

    安装步骤很简单,首先启用usb.jffs.等. 然后: mkdir -p /jffs/opt mount -o bind /jffs/opt /opt wget -O - http://pkg.ent ...

  6. ftp软件中保持连接命令CWD、PWD、LIST、NOOP四个操作命令解析

    转自:http://www.aspjzy.com/A/148.html 各位站长都知道,我们在维护网站的时候,经常需要一直保持ftp连接状态,这个时候在很多ftp客户端软件中都有一个保持全局连接的选项 ...

  7. 物联网架构成长之路(30)-Spring Boot Admin微服务WebUI监控

    0. 前言 一个完整的微服务解决方案包含了许多微服务,基于我们需要观察各个微服务的运行状态,因此Spring Boot 生态提供了Spring Boot Admin 这个组件来实现微服务管理WEB U ...

  8. Docker容器启动lnmp环境下的mysql服务时报"MySQL server PID file could not be found"错误解决办法

    我在自己的mac笔记本上装了一个docker,并在docker容器中安装了lnmp环境,经常会遇到在使用"lnmp restart"命令启动lnmp服务的时候,mysql服务启动失 ...

  9. ffmpeg转码器移植VC的project:ffmpeg for MFC

    本文介绍一个自己做的FFMPEG移植到VC下的开源project:ffmpeg for MFC.本project将ffmpegproject中的ffmpeg转码器(ffmpeg.c)移植到了VC环境下 ...

  10. C++ 函数模板默认的模板参数

    函数的默认模板参数 你可以为模板参数定义默认值,它们被称作 default template arguments(默认模板参数). 它们甚至可以指向前一个模板参数. 1. 可以直接使用 operato ...