A15683 | Two Towers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are two towers consisting of blocks of two colors: red and blue. Both towers are represented by strings of characters B and/or R denoting the order of blocks in them from the bottom to the top, where B corresponds to a blue block, and R corresponds to a red block.
 These two towers are represented by strings BRBB and RBR.You can perform the following operation any number of times: choose a tower with at least two blocks, and move its top block to the top of the other tower.
 The pair of towers is beautiful if no pair of touching blocks has the same color; i. e. no red block stands on top of another red block, and no blue block stands on top of another blue block.
You have to check if it is possible to perform any number of operations (possibly zero) to make the pair of towers beautiful.
 These two towers are represented by strings BRBB and RBR.You can perform the following operation any number of times: choose a tower with at least two blocks, and move its top block to the top of the other tower.
 The pair of towers is beautiful if no pair of touching blocks has the same color; i. e. no red block stands on top of another red block, and no blue block stands on top of another blue block.
You have to check if it is possible to perform any number of operations (possibly zero) to make the pair of towers beautiful.
输入格式
The first line contains one integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases.
Each test case consists of three lines:
- the first line contains two integers $n$ and $m$ ( $1 \le n, m \le 20$ ) — the number of blocks in the first tower and the number of blocks in the second tower, respectively;
- the second line contains $s$ — a string of exactly $n$ characters B and/or R, denoting the first tower;
- the third line contains $t$ — a string of exactly $m$ characters B and/or R, denoting the second tower.
Each test case consists of three lines:
- the first line contains two integers $n$ and $m$ ( $1 \le n, m \le 20$ ) — the number of blocks in the first tower and the number of blocks in the second tower, respectively;
- the second line contains $s$ — a string of exactly $n$ characters B and/or R, denoting the first tower;
- the third line contains $t$ — a string of exactly $m$ characters B and/or R, denoting the second tower.
输出格式
For each test case, print YES if it is possible to perform several (possibly zero) operations in such a way that the pair of towers becomes beautiful; otherwise print NO.
You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).
You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).
输入输出样例
输入 #1
4 4 3 BRBB RBR 4 7 BRBR RRBRBRB 3 4 RBR BRBR 5 4 BRBRR BRBR
输出 #1
YES YES YES NO
In the first test case, you can move the top block from the first tower to the second tower (see the third picture).
In the second test case, you can move the top block from the second tower to the first tower $6$ times.
In the third test case, the pair of towers is already beautiful.
In the second test case, you can move the top block from the second tower to the first tower $6$ times.
In the third test case, the pair of towers is already beautiful.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted