重点词汇:
terminate v.结束,终止,达到终点站。
layout n.布局,设计,排版。
maze n,迷宫。v.发晕,使迷惑。
出处: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 Acm是一个宝藏探索家,这一次他又在探索了。这一次他来到了一个有一些门的特殊迷宫(迷宫中最多有5个门,分别用'A', 'B', 'C', 'D', 'E'代表)。 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 为了找到宝藏,Acm需要打开这些门。 然而,要打开这些门他第一部需要在迷宫中找到全部门的钥匙(至少一个钥匙)。 举个例子,如果开A门需要3把钥匙,为了开这个门他需要先找到这3把钥匙 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, (用三个“a"代表在迷宫中门"A"的三把钥匙) 现在编写一个程序告诉Acm他是否能找到宝藏。注意Acm在迷宫中只能往上走,往下走,往左和右走 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.输入包含多组数据。每一组数据的第一行包含两个整数 M 和N ,代表着迷宫的大小。 接下来的M行给出迷宫的布局,每一行包含N个元素。每一个元素有如下情况:“X”(代表一道墙),
“。”(代表一个空地区),“S”(代表Acm的出发点),“G”(宝藏的地点),“A,B,C,D,E”(代表门),“a,b,c,d,e”(代表门的钥匙)。以输入两个0为结束。
输出:
For each test case, in one line output "YES" if Acm can find the treasure, or "NO" otherwise. 对于每一组测试数据,输出一行“YES”当Acm能找到宝藏,否则输出"NO"。样例输入:
4 4 S.X. a.X. ..XG .... 3 4 S.Xa .aXB b.AG 0 0
样例输出:
YES NO