CF1644A.Doors and Keys

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

骑士站在一条狭长走廊的入口处,公主正在走廊尽头等待。

走廊中有三扇门:一扇红门、一扇绿门和一扇蓝门。这三扇门依次排列(但顺序可能不同)。要到达下一扇门,骑士必须先打开当前这扇门。

每扇门只能用对应颜色的钥匙打开。因此,走廊中还放置了三把钥匙:一把红钥匙、一把绿钥匙和一把蓝钥匙。要打开某扇门,骑士必须先拾取该门颜色对应的钥匙。

骑士拥有一张走廊的地图,该地图可表示为一个由六个字符组成的字符串:

  • R、G、B 分别表示红门、绿门、蓝门;
  • r、g、b 分别表示红钥匙、绿钥匙、蓝钥匙。

上述六个字符在该字符串中各出现且仅出现一次。

骑士起始于走廊的起点——即地图的最左侧。

给定一张走廊地图,请判断骑士是否能打开所有门,并最终在走廊尽头与公主相遇。

输入格式

The first line contains a single integer tt (1≤t≤7201 \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.

第一行包含一个整数 tt(1≤t≤7201 \le t \le 720)—— 表示测试用例的数量。

每个测试用例由一个字符串组成。字符串中的每个字符为 R、G、B(代表门)或 r、g、b(代表钥匙)之一,且每种字符恰好出现一次。

输出格式

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

对于每个测试用例,如果骑士能够打开所有门,则输出 YES;否则输出 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.

在第一个测试用例中,骑士首先收集所有钥匙,然后用这些钥匙打开所有门。

在第二个测试用例中,骑士正前方有一扇红色的门,但他没有对应的钥匙。

在第三个测试用例中,每扇门前都放置着对应门的钥匙,因此骑士共三次分别收集钥匙并立即使用。

在第四个测试用例中,骑士无法打开蓝色的门。

输入解题思路,AI测评打分。不知道怎么写?

首页