A14944 | Doors and Keys
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted