309209: CF1644A. Doors and Keys

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Doors and Keys

题意翻译

有一个骑士站在一条走廊的左端,在走廊的右端,一位公主正在等待他的到来。 在来到这里之前,骑士就了解到,这条走廊一共有三扇门:红门、绿门和蓝门。分别对应这三扇门的钥匙分别是红钥匙、绿钥匙和蓝钥匙。他还拥有一张这条走廊的地图,其可以转化成一个仅包含以下 $6$ 个字符的字符串: - `R`、`G`、`B`:分别表示红门、绿门和蓝门。 - `r`、`g`、`b`:分别表示红钥匙、绿钥匙和蓝钥匙。 骑士能够经过一扇门,当且仅当骑士拥有与其对应的钥匙。由于公主不愿意等太久,因此骑士**只能一直向右端走,不能回头**。 请判断骑士能否走到走廊的右端和公主会合。 数据范围:$t$ 组数据,$1\leqslant t\leqslant 720$。 Translated by Eason_AC

题目描述

The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it. In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before. Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color. The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: - R, G, B — denoting red, green and blue doors, respectively; - r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once. The knight is standing at the beginning of the hallway — on the left on the map. Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway.

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \le t \le 720 $ ) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once.

输出格式


For each testcase, print YES if the knight can open all doors. Otherwise, print NO.

输入输出样例

输入样例 #1

4
rgbBRG
RgbrBG
bBrRgG
rgRGBb

输出样例 #1

YES
NO
YES
NO

说明

In the first testcase, the knight first collects all keys, then opens all doors with them. In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it. In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times. In the fourth testcase, the knight can't open the blue door.

Input

题意翻译

有一个骑士站在一条走廊的左端,在走廊的右端,一位公主正在等待他的到来。 在来到这里之前,骑士就了解到,这条走廊一共有三扇门:红门、绿门和蓝门。分别对应这三扇门的钥匙分别是红钥匙、绿钥匙和蓝钥匙。他还拥有一张这条走廊的地图,其可以转化成一个仅包含以下 $6$ 个字符的字符串: - `R`、`G`、`B`:分别表示红门、绿门和蓝门。 - `r`、`g`、`b`:分别表示红钥匙、绿钥匙和蓝钥匙。 骑士能够经过一扇门,当且仅当骑士拥有与其对应的钥匙。由于公主不愿意等太久,因此骑士**只能一直向右端走,不能回头**。 请判断骑士能否走到走廊的右端和公主会合。 数据范围:$t$ 组数据,$1\leqslant t\leqslant 720$。 Translated by Eason_AC

加入题单

算法标签: