| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 数据结构与算法 -> A. Doors and Keys -> 正文阅读 |
|
[数据结构与算法]A. Doors and Keys |
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output 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:
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. Input The first line contains a single integer?tt?(1≤t≤7201≤t≤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. Output For each testcase, print?YES?if the knight can open all doors. Otherwise, print?NO. Example input Copy 4 rgbBRG RgbrBG bBrRgG rgRGBb output Copy YES NO YES NO Note 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. 解题说明:水题,直接遍历,确保在碰见某种颜色门前能拿到对应钥匙,否则无法通过。
|
|
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/26 11:51:12- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |