hdu1312题解
这道题从名称来看看不出什么。
所以我们先读一下题干
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题解的更多相关文章
- HDU-1312题解(DFS)
HDU-1312-DFS Written by Void-Walker 2020-02-01 09:09:25 1.题目传送门:http://acm.hdu.edu.cn/showproblem ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
随机推荐
- lvs负载均衡配置
三台server的ip direct_server:192.168.248.128 real_server1:192.168.248.130 real_server2:192. ...
- 谈谈HashSet的存储原理及为什么重写equals必须重写hashcode方法
HashSet的存储原理: 1.将要传入的数据根据系统的hash算法得到一个hash值: 2.根据hash值可以得出该数据在hash表中的位置: 3.判断该位置上是否有值,没有值则把数据插入进来:如果 ...
- 010.CI4框架CodeIgniter, autoload自动加载自己的helper函数类
01.自己定义了一个helper类,里面有个函数用来输出 02.定义一个Controller基本类,我们以后用到的Controllers类都继承自这个类.其中自动加载helper函数如图所示: 03. ...
- Python 日志模块详解
前言 我们知道查看日志是开发人员日常获取信息.排查异常.发现问题的最好途径,日志记录中通常会标记有异常产生的原因.发生时间.具体错误行数等信息,这极大的节省了我们的排查时间,无形中提高了编码效率.所以 ...
- TextBoxFor()扩展方法
1.扩展方法 public static class TextBoxForHelper { public static MvcHtmlString CreateTextBoxFor<TModel ...
- C++(五)构造函数
//构造函数的作用:就是在函数被创建时使用特定的值构造对象,将对象初始化为一个特定的初始状态//例如在构造一个clock类对象的时候,将初始的时间设定为0:0:0//构造函数的名必须与类名相同,不能定 ...
- Node.js 加载静态资源css,js等不显示问题的解决方法
一,原因 1,没有响应到css等文件 2,响应类型是由文件的后缀名决定 (1)html的请求头 Content-Type : text/html ; charset=utf-8 (2) CSS的请求头 ...
- Python练习题3
1.九九乘法表 li = [1,2,3,4,5,6,7,8,9] for i in li: for j in li: if i >= j: print(i,'*',j,'=',i*j,end=& ...
- 【转】R语言函数总结
原博: R语言与数据挖掘:公式:数据:方法 R语言特征 对大小写敏感 通常,数字,字母,. 和 _都是允许的(在一些国家还包括重音字母).不过,一个命名必须以 . 或者字母开头,并且如果以 . 开头, ...
- 3.python进制及其之间的转换