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

 #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. Ajax的进阶学习(二)

    JSON和JSONP 如果在同一个域下,$.ajax()方法只要设置dataType属性即可加载JSON文件.而在非同域下,可以使用JSONP,但也是有条件的. Ajax进阶.html: <!D ...

  2. mysql之select(一)

    select 初始准备工作: 1.建木瓜库并选中 create database mugua; use mugua; 2.创建商品表.栏目表.品牌表 create table goods ( good ...

  3. 23种设计模式学习一(单列模式)singleton

    单列模式的类(单线程下的) class Singleton { private static Singleton instance; private Singleton() { } public st ...

  4. 【poj3243-Clever Y】高次同余方程-拓展BabyStepGiantStep

    http://poj.org/problem?id=3243 题意:给定X,Z,K,求一个最小的Y满足XY mod Z = K. 关于拓展BSGS的详细解释我写了一篇博文:http://www.cnb ...

  5. maven依赖的全局排除

    今天遇到要全局排除一个maven依赖,因为Maven本身没有全局排除依赖的办法, 参考了同事人英写的一篇博文(可以看这里http://my.oschina.net/liuyongpo/blog/177 ...

  6. 15 things to talk about in a healthy relationship

    15 things to talk about in a healthy relationship男女交往中可以谈论的15个话题 1. Your Daily Activities 1. 你的日常活动 ...

  7. MyBatis学习总结_19_Mybatis传多个参数(三种解决方案)

    据我目前接触到的传多个参数的方案有三种. 第一种方案  DAO层的函数方法  Public User selectUser(String name,String area); 对应的Mapper.xm ...

  8. Android 实现全屏、无标题栏

    实现全屏无标题栏: 1.在xml文件中进行配置 AndroidManifest.xml中,找到需要全屏或设置成无标题栏的Activity,在该Activity进行如下配置即可. 实现全屏效果: and ...

  9. MyEclipse6.6 汉化过程

                                                                                                         ...

  10. Babel 6 配置

    Babel 6 较之前版本有些变化,几个比较重要的点. npm package babel 已经不在使用了,分成了下列几个 package babel-cli, 适用于命令行 babel-core, ...