Maze(https://acs.jxnu.edu.cn/problem/NOIOPJCH02051159)

题目:

Maze

 2000ms  65536K

描述:

Acm, a treasure-explorer, is exploring again. This time he is in a special maze, in which there are some doors (at most 5 doors, represented by 'A', 'B', 'C', 'D', 'E' respectively). In order to find the treasure, Acm may need to open doors. However, to open a door he needs to find all the door's keys (at least one) in the maze first. For example, if there are 3 keys of Door A, to open the door he should find all the 3 keys first (that's three 'a's which denote the keys of 'A' in the maze). Now make a program to tell Acm whether he can find the treasure or not. Notice that Acm can only go up, down, left and right in the maze.

输入:

The input consists of multiple test cases. The first line of each test case contains two integers M and N (1 < N, M < 20), which denote the size of the maze. The next M lines give the maze layout, with each line containing N characters. A character is one of the following: 'X' (a block of wall, which the explorer cannot enter), '.' (an empty block), 'S' (the start point of Acm), 'G' (the position of treasure), 'A', 'B', 'C', 'D', 'E' (the doors), 'a', 'b', 'c', 'd', 'e' (the keys of the doors). The input is terminated with two 0's. This test case should not be processed.

输出:

For each test case, in one line output "YES" if Acm can find the treasure, or "NO" otherwise.

样例输入:

4 4 
S.X. 
a.X. 
..XG 
.... 
3 4 
S.Xa 
.aXB 
b.AG 
0 0

样例输出:

YES 
NO

注释:

Source: POJ Monthly,Wang Yijie

翻译:

描述:

Acm,一个宝藏探索家,正在又一次进行探索,这次他在一个特殊的迷宫,这里有一些门(最多无扇门,依次用'A', 'B', 'C', 'D', 'E'代表 )。为了找到宝藏,Acm 也许需要开门,然而,为了开门他首先需要找到在迷宫里所有门的钥匙(至少一把)。例如,如果A门有三把钥匙,要开门他应该首先找到三把钥匙,(迷宫中三个‘a’是‘A’门的钥匙)

现在编写一个程序告诉Acm他是否能找到宝藏,注意,在迷宫中Acm仅可以上,下,左,右移动。

输入:

输入由多组测试用例组成,每个测试用例的第一行包含两个整数M和N(1 < N, M < 20),指出迷宫的大小,接下来的M行给出迷宫的布局,每一行包含N个字符。字符是一下之一:‘X’(一堵墙,探索者不能进入)'.'(空块),'S'Acm开始的点),'G'(宝藏的位置),'A', 'B', 'C', 'D', 'E'(门),'a', 'b', 'c', 'd', 'e'(门的钥匙),输入以两个0终结。不应处理测试用例。

输出:

对于每个测试用例,如果Acm可以找到宝藏,则在第一行输出 "YES",否则输出"NO"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值