这道题从名称来看看不出什么。

所以我们先读一下题干

There is a rectangular room, covered with square tiles. Each tile is colored either red or black.
A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he
can't move on red tiles, he can move only on black tiles.Write a program to count the number of
black tiles which he can reach by repeating the moves described above.

Input:

The input consists of multiple data sets. A data set starts with a line containing two positive
integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W
and H are not more than 20.There are H more lines in the data set, each of which includes W
characters. Each character represents the color of a tile as follows.
'.' - a black tile;'#' - a red tile;'@' - a man on a black tile(appears exactly once in a data set) .
Output:
For each data set, your program should output a line which contains the number of tiles he
can reach from the initial tile (including itself).
Sample Input:

一个人在长方形的房间里,房间里铺着红色或黑色的方形的地砖。他只能走到黑色地砖上,他每次可以移动到他周边四块地砖中的一块、但他不能踩在红色地砖上、只能踩在黑色地砖上。写个程序,数出他可以走到多少个黑色的地砖。

输入:

两个正整数W和H,分别依次对应X方向和Y方向,W和H都不超过20,H行中包含W个数,“.”代表黑色地砖,“#”代表红色地砖,“@”代表那个人站在黑色地砖上(每个数据表格中仅出现一次)。

输出:

把他能到达(包括他自己)的黑色地砖数量在一行输出。

很明显这是一道广搜题,我们不妨先定义一个队列,把初始位置入队。

然后判断,如果是则sum++(sum初始为0),接着把周围的四个数入队,然后出队。否则直接出队;

这里注意,入过队的一定要做标记,直到队列为空为止。

最后输出sum的值,便是结果。

hdu1312题解的更多相关文章

  1. HDU-1312题解(DFS)

    HDU-1312-DFS Written by Void-Walker    2020-02-01 09:09:25 1.题目传送门:http://acm.hdu.edu.cn/showproblem ...

  2. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  3. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  4. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  5. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  6. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  9. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

随机推荐

  1. java.jvm调优

    _amazing~ 基本: 整理:

  2. 009.CI4框架CodeIgniter, 网页访问GET的URL参数获取,分段输出URL参数

    01.代码如下,我们给在PHP CI4框架中定义了一个show函数,并给了3个参数,代码如下: <?php namespace App\Controllers\System; use App\C ...

  3. 006.Delphi插件之QPlugins,多服务演示

    演示效果如下 演示工程,全部就一个文件,代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messages, System.SysUt ...

  4. Sqlserver自动备份bat

    1.bat文件 @echo off echo 删除30天前的备分文件和日志 forfiles /p /c "cmd /c del @path" \Tools\Binn echo 数 ...

  5. react 如何引入打印控件 CLodop

    下载插件,官网地址 http://www.lodop.net/download.html  ,选择综合版,解压下载的文件.直接点击 安装,很简单,就不一一说明了. 复制下面几个文件,到react项目中 ...

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-eject

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  7. centos yum安装redis,nginx

    先安装源 yum install epel-release 之后 分别安装redis,nginx

  8. tensorflow学习笔记(三)常用函数

    上一篇简单介绍了tensorflow的基本操作,这一篇介绍一些常用的函数. tf.constant() tf.constant ( value , dtype = None , shape = Non ...

  9. 022-PHP数组排序asort

    <?php // 构造一个数组变量 $users = array("bob" => "Yobert", "steve" => ...

  10. pop3&smtp

    pop3&smtp pop3 Post Office Protocol - Version 3 pop3协议是离线邮件协议,是客户端取邮件用的. 默认监听在TCP:110端口. POP3会话有 ...