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

 #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. Mac Air maven 环境配置

    mave 的配置 检出项目遇到问题: Could not calculate build plan: Failure to transfer org.apache.maven.plugins:mave ...

  2. PHP函数中默认参数的的写法

    函数可以定义 C++ 风格的标量参数默认值,如下所示: Example #3 在函数中使用默认参数 <?php function makecoffee($type = "cappucc ...

  3. php curl 分离header和body信息

    php中可以通过curl来模拟http请求,同时可以获取http response header和body,当然也设置参数可以只获取其中的某一个.当设置同时获取response header和body ...

  4. ibatis2.3中#和$符号的区别(转)

    在Ibatis中我们使用SqlMap进行Sql查询时需要引用参数,在参数引用中遇到的符号#和$之间的区分为,#可以进行与编译,进行类型匹配,而$不进行数据类型匹配,例如: select * from ...

  5. java开发--JavaScript

    http://www.cnblogs.com/hongten/archive/2011/03/21/1990121.html JavaScript表单验证电话号码,判断一个输入量是否为电话号码,通过正 ...

  6. 使用 JAX-RS 简化 REST 应用开发

    本文将详细介绍 Java EE 6 中所引入的对 JSR-311 (JAX-RS : Java API for RESTful Web Services) 的支持,并通过一个完整的示例应用程序展示 J ...

  7. 处理11gR2 RAC集群资源状态异常INTERMEDIATE,CHECK TIMED OUT

    注意节点6,7的磁盘CRSDG的状态明显不正常.oracle@ZJHZ-PS-CMREAD-SV-RPTDW06-DB-SD:~> crsctl status resource -t |less ...

  8. 10位IT领袖给应届毕业生的10条忠告

    10位IT领袖给应届毕业生的10条忠告,在走向独立和自主的伟大征程中,吸取他们的经验. 在毕业生们迈出象牙塔之时,他们应该听从哪些人的建议?在走向独立和自主的伟大征程中,他们该吸取哪些教训?听一听各领 ...

  9. Eclipse插件安装与使用 —— Properties Editor

    一.下载     首先当然是下载插件啦! 下载地址:http://sourceforge.jp/projects/propedit/downloads/40156/jp.gr.java_conf.us ...

  10. Java 异常 —— Bad version number in .class file

    把一个项目拷贝到另一个环境,运行时报错: Caused by: java.lang.UnsupportedClassVersionError: Bad version number in .class ...