解题思路:好久没写搜索了,练练手,陶冶情操。不多说,直接贴代码:

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = ;
int dir[][] = {-, -, -, , -, , , -,
, , , -, , , , };
char gg[maxn][maxn];
int m, n; void DFS(int x, int y, int id)
{
if(x < || x > m || y < || y > n || gg[x][y] == '*') return ;
gg[x][y] = '*';
for(int i = ; i < ; i++)
{
int xx = x + dir[i][];
int yy = y + dir[i][]; if(xx < || xx > m || yy < || yy > n || gg[xx][yy] == '*') continue;
DFS(xx, yy, id);
}
return ;
}
int main()
{
int cnt;
while(~scanf("%d %d", &m, &n) && m)
{
memset(gg, '#', sizeof(gg));
for(int i = ; i <= m; i++)
for(int j = ; j <= n; j++) scanf(" %c", &gg[i][j]); cnt = ;
for(int i = ; i <= m; i++)
for(int j = ; j <= n; j++)
if(gg[i][j] == '@') DFS(i, j, ++cnt);
printf("%d\n", cnt);
}
return ;
}

UVa572 - Oil Deposits的更多相关文章

  1. UVa572 Oil Deposits DFS求连通块

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

  2. UVA572 Oil Deposits DFS求解

    小白书上经典DFS题目. 1. 递归实现 // from: https://www.cnblogs.com/huaszjh/p/4686092.html #include <stdio.h> ...

  3. [C++]油田(Oil Deposits)-用DFS求连通块

    [本博文非博主原创,均摘自:刘汝佳<算法竞赛入门经典>(第2版) 6.4 图] [程序代码根据书中思路,非独立实现] 例题6-12 油田(Oil Deposits,UVa572) 输入一个 ...

  4. Oil Deposits

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

  5. Oil Deposits(dfs)

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

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

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

  7. uva 572 oil deposits——yhx

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

  8. hdu 1241:Oil Deposits(DFS)

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

  9. hdu1241 Oil Deposits

    Oil Deposits                                                 Time Limit: 2000/1000 MS (Java/Others)  ...

随机推荐

  1. JavaScript call和apply的用法

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  2. c# string.Format用法总结

    文章出处:http://www.cnblogs.com/7788/archive/2009/05/13/1455920.html 先举几个简单的应用案例: 1.格式化货币(跟系统的环境有关,中文系统默 ...

  3. ***iOS开发中@selector的理解与应用

    @selector 是什么? 1一种类型 SEL2代表你要发送的消息(方法), 跟字符串有点像, 也可以互转.: NSSelectorFromString() / NSSelectorFromStri ...

  4. Xcode 创建静态库和动态库

    1.linux中静态库和动态库区别: 库从本质上来说是一种可执行代码的二进制格式,可以被载入内存中执行.库分静态库和动态库两种. 静态库:这类库的名字一般是libxxx.a:利用静态函数库编译成的文件 ...

  5. JavaScript基础之函数与数组

     函数    函数的基本概念 为完成某一功能的程序指令(语句)的集合,称为函数.有的程序员把函数称为方法,希望大家不要被这两个名词搞晕了. 函数分为:自定义函数.系统函数(经常查看js帮助手册). j ...

  6. 【poj2778-DNA Sequence】AC自动机+矩阵乘法

    题意: (只含AGCT)给定m个病毒串,让你构造一个长度为n的字符串(也只含有AGCT),问有多少种方案.n很大:1<=n<=2000000000 题解: 用病毒串建立AC自动机(num个 ...

  7. http://blog.sina.com.cn/s/blog_5b9b4abe01017638.html

    http://blog.sina.com.cn/s/blog_5b9b4abe01017638.html

  8. 本地替换文件读取MYSQL密码

    Mysql 的密码默认是存储在/data/mysql/下面的三个文件中:user.MYD,user.frm,user.MYI 先把这三个文件下载到本地,然后替换本地的这三个文件 使用net stop ...

  9. 给View换字体

    注意,给View换字体是直接换.在Delegate里换的只是某一列的字体 class delegate : public QStyledItemDelegate { public: ) : QStyl ...

  10. Qt源代码分析

    记下好文章,慢慢看,然后加上自己心得: http://www.cnblogs.com/hicjiajia/archive/2011/08/27/2155512.html Qt源码分析之信号和槽机制ht ...