描述:
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
翻译:
迷宫
Acm,一个珠宝探索者,正在探索。这次他正在一个特殊的迷宫里,在里面有一些门(至少五扇门,分别用A B C DE来表示)为了找到珠宝,Acm可能需要去打开几扇门。然而,去打开门他首先需要在迷宫里找到所有门的钥匙(至少一把)。例如,如果门A有三把钥匙,去打开门他首先应该找到所有的三把钥匙(那是A的贡献迷宫的钥匙)。
现在要做一个项目来告诉Acm只能上升,下降,向左或向右。
输入:
输入包括多个测试案例。每个测试案例的第一行包括两个整数M和N(1<N,M<20),N指的是迷宫的大小。下个M行给出了迷宫的放置,每行包含N个数字。A是以中的一个:‘X’(墙的阻碍,探索者不能进入),‘.’(一个空的阻碍),‘S’(Acm的起始点),‘G’(珠宝的位置),‘A’‘B’‘C’‘D’,‘E’(门),‘a’‘b’‘c’‘d’‘e’(门的钥匙)。这个输入是被两个0所确定的。剩余的案例不应该被占据。
输出:
对于每个测试案例,如果Acm能够找到珠宝的话,在每一行输出“YES”,否则输出“NO”。
样例输入:
4 4
S.X.
a.X.
..XG
....
3 4
S.Xa
.aXB
b.AG
0 0
样例输出:
YES
NO