因为这道题中给的数据比较小,所以可以直接用枚举的方式进行dfs搜索,每出现一个‘@’,就进行一次dfs的搜索,将所有相邻的‘@’全部变成‘*’。

#include"iostream"
#include"stdio.h"
#include"algorithm"
#include"string.h"
#include"cmath"
#include"queue"
#define mx 105
using namespace std;
char map1[mx][mx];
int dir[][]={{,},{,-},{,},{-,},
{-,-},{-,},{,},{,-}};
int n,m,num;
bool judge(int x,int y)
{
if(x>=&&x<n&&y>=&&y<m&&map1[x][y]=='@')return true;
return false;
}
void dfs(int x,int y)
{
int i,dx,dy;
for(i=;i<;i++)
{
dx=x+dir[i][];
dy=y+dir[i][];
if(judge(dx,dy)) {map1[dx][dy]='*';dfs(dx,dy);}
}
}
int main()
{
while(cin>>n>>m,n||m)
{
int i,j;
num=;
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
cin>>map1[i][j];
}
}
for(i=;i<n;i++)
for(j=;j<m;j++)
{
if(judge(i,j)) {num++;map1[i][j]='*';dfs(i,j);}
}
cout<<num<<endl;
}
return ;
}

hdu 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. HDU 1241 Oil Deposits(石油储藏)

    HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Probl ...

  4. (深搜)Oil Deposits -- hdu -- 1241

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

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

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

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

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

  7. Oil Deposits HDU - 1241 (dfs)

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

  8. hdu 1241:Oil Deposits(DFS)

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

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

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

随机推荐

  1. 【转】SQL中内连接和外连接

    如表     -------------------------------------------------     table1 | table2 |     ----------------- ...

  2. Java for LeetCode 151 Reverse Words in a String

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  3. HDU1250 高精度斐波那契数列

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. 基于gitosis的Git云端服务器配置

    (本文需要自己实践,由于时间关系,我仅仅是做了整理和快速的练习,至于笔记中的账号和ip域名都是我参考文章中的.如果读者有任何问题欢迎留言和发邮件到luoquantao@126.com) 硬件:云端阿里 ...

  5. Hadoop 2.x HDFS新特性

    Hadoop 2.x HDFS新特性 1.HDFS联邦    2. HDFS HA(要用到zookeeper等,留在后面再讲)    3.HDFS快照 回顾: HDFS两层模型     Namespa ...

  6. Python中通过cx_oracle操作ORACLE数据库的封闭函数

    哈哈,看来我的SQL自动化发布,马上就全面支持ORACLE,MYSQL,POSTGRESQL,MSSQL啦... http://blog.csdn.net/swiftshow/article/deta ...

  7. Lua和C之间的交互

    转自:http://blog.csdn.net/sumoyu/article/details/2592693 (一) Lua 调C函数 什么样类型的函数可以被Lua调用   typedef int ( ...

  8. 用sqlplus登陆数据库时,oracle 11g出现ORA-12514问题

    转自:http://zhidao.baidu.com/question/144648216.html 启动服务 然后在sqlplus / as sysdba;执行启动startup nomount;a ...

  9. Digital Image Processing 学习笔记3

    第三章 灰度变换与空间滤波 3.1 背景知识 3.1.1 灰度变换和空间滤波基础 本章节所讨论的图像处理技术都是在空间域进行的.可以表示为下式: $$g(x, y) = T[f(x,y)]$$ 其中$ ...

  10. jq验证插件validate

    博客: http://www.cnblogs.com/linjiqin/p/3433635.html http://blog.csdn.net/windxxf/article/details/7520 ...