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

所以我们先读一下题干

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. tools.quartz.about

    官方网站,中文文档,demo,  参考零, 参考一, 参考二, 参考三, 参考四 , 参考五 ,文档下载 .

  2. 关于 vue.config.js 文件的配置

    相关文档: https://cli.vuejs.org/zh/config/#vue-config-js

  3. 6.安装telnet服务

    yum list telnet* 列出telnet相关的安装包 yum install telnet-server 安装telnet服务 yum install telnet.* 安装telnet客户 ...

  4. 在ubuntu中使用ipython

    python自带的shell实在是不怎么好用 大家可以用一下ipython这个软件,它可以自动缩进,补齐,语法高亮等 安装办法: sudo apt install ipython #这个是安装2.7的 ...

  5. Spring Aop 原理分析

    @EnableAspectJAutoProxy Aop功能开启注解 为容器中导入 @Import(AspectJAutoProxyRegistrar.class)组件,在其重写方法中为 ioc容器 注 ...

  6. UVA - 524 Prime Ring Problem(素数环)(回溯法)

    题意:输入n,把1~n组成个环,相邻两个数之和为素数. 分析:回溯法. #pragma comment(linker, "/STACK:102400000, 102400000") ...

  7. UVA - 1572 Self-Assembly(图论模型+拓扑排序)

    题意:判断利用给出的正方形是否能拼接出无限延伸的结构. 分析:正方形上的字母看做点,正方形看做有向边. 例如: 若上下两个正方形能拼接,需要B+~C+是个有向边. 对输入的处理是:把A+,A-分别映射 ...

  8. sprintf与sscanf用法举例

    一.sscanf 从tmp中读取a,b,c. int main(){ ]; int a; double b; ]; while(gets(tmp) != NULL){ sscanf(tmp, &quo ...

  9. CSS - 美化字体 => CSS的-font-smoothin属性优化

    body{     margin: 0;     font-family: Arial, Helvetica, sans-serif;     line-height: 1.2em;     back ...

  10. Arduino 的读串口与写串口

    //准备一下             while(Serial.available()>0)        WifiSerial.write(Serial.read());         wh ...