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.
【Acm,一位寻宝人,再次在寻找宝藏。这次他在一个特殊的迷宫,迷宫内有些门(最多有5扇门,依次用A,B,C,D,E代表)。为了找到宝藏,Acm需要打开门。然而,为了打开一扇门,首先他需要在迷宫找到门的所有钥匙(至少一个)。举个例子,如果门A有3把钥匙,他必须先找到3把钥匙才能打开门(三把钥匙a在迷宫内标志着门A的钥匙)。现在,请编写一个程序去告诉Acm他是否能找到宝藏。请注意Acm在迷宫只能上升,下降,向左,向右。】
输入:
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(1 < N, M < 20),这代表着迷宫的大小。接下来就有M行告诉迷宫的布局,每行有N个符号。符号X(一面墙,寻宝人不能通过),符号.(空格),符号S(Acm的起点),符号G(宝藏的位置),符号ABCDE(门),符号abcde(门对应的钥匙)。如果输入是两个0,则运行终止。】
输出:
For each test case, in one line output "YES" if Acm can find the treasure, or "NO" otherwise.
【对于每组测试样例,如果Acm能找到宝藏输出YES否则NO】
样例输入:
4 4 S.X. a.X. ..XG .... 3 4 S.Xa .aXB b.AG 0 0
样例输出:
YES NO

7万+

被折叠的 条评论
为什么被折叠?



