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或 ...
随机推荐
- 0108 spring的申明式事务
背景 互联网的金融和电商行业,最关注数据库事务. 业务核心 说明 金融行业-金融产品金额 不允许发生错误 电商行业-商品交易金额,商品库存 不允许发生错误 面临的难点: 高并发下保证: 数据一致性,高 ...
- Service总结
Service Service的应用场景,以及和Thread区别 开启Service的两种方式以及区别 Service基础 Service是什么? Service(服务)是一个可以在后台长时间运行而没 ...
- Maven的原理和使用
一.Maven能做什么 1.假设我们有10个项目,都需要引入spring core模块,那么需要十份重复的Spring Core.jar和commons-logging.jar 使用Maven:mav ...
- linux后台运行jar
1. 在linux服务器上运行Jar文件时通常的方法是: $ java -jar test.jar 这种方式当ssh窗口关闭时,程序中止运行,或者是运行时没法切出去执行其他任务 2. 保持程序后台运行 ...
- 吴裕雄--天生自然java开发常用类库学习笔记:Arrays
import java.util.* ; public class ArraysDemo{ public static void main(String arg[]){ int temp[] = {3 ...
- 147-PHP strip_tags函数,剥去字符串中的 HTML 标签(一)
<?php $html=<<<HTM <title>PHP输出HTML代码</title> <body> <a href=#>转 ...
- 076-PHP数组修改元素值
<?php $arr=array(98,'hello',67,'A',85,NULL); //定义一个数组 echo '输出数组修改元素之前的详细信息:<br />'; print_ ...
- tomcat conf目录下server.xml详解
一. 一个server.xml配置实例 1 <Server port="8005" shutdown="SHUTDOWN"> 2 <Lis ...
- SpringBoot学习(五)——Profile
Profile是Spring对不同环境(例如开发人用开发环境,测试人员用测试环境)提供不同配置功能的支持,可以通过激活,指定参数等方式快速切换环境 1.多profile文件形式 格式:applicat ...
- springboot - 映射 HTTP Response Status Codes 到自定义 JSP Error 页面
1.总览 2.代码 1).pom.xml <dependencies> <dependency> <groupId>org.springframework.boot ...