CF1795A.Two Towers
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
有两座由两种颜色(红色和蓝色)的方块组成的塔。每座塔都用一个仅包含字符 B 和/或 R 的字符串表示,字符串中字符从左到右依次对应塔中从底到顶的方块顺序,其中 B 表示蓝色方块,R 表示红色方块。
这两座塔分别由字符串 BRBB 和 RBR 表示。
你可以执行以下操作任意多次:选择一座至少含有两个方块的塔,并将其最顶端的方块移动到另一座塔的顶端。

若一对塔中不存在任何相邻(即上下紧贴)的同色方块,则称该对塔是“优美的”;即:不存在红色方块叠在另一个红色方块之上,也不存在蓝色方块叠在另一个蓝色方块之上。
你需要判断:是否可以通过执行任意次数(包括零次)的上述操作,使得这对塔变得优美。
输入格式
The first line contains one integer t (1≤t≤1000) — the number of test cases.
Each test case consists of three lines:
- the first line contains two integers n and m (1≤n,m≤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.
第一行包含一个整数 t(1≤t≤1000)—— 测试用例的数量。
每个测试用例由三行组成:
- 第一行包含两个整数 n 和 m(1≤n,m≤20)—— 分别表示第一座塔和第二座塔中的方块数量;
- 第二行包含字符串 s —— 一个恰好由 n 个字符 B 和/或 R 组成的字符串,表示第一座塔;
- 第三行包含字符串 t —— 一个恰好由 m 个字符 B 和/或 R 组成的字符串,表示第二座塔。
输出格式
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).
对于每个测试用例,如果可以通过执行若干次(可能为零次)操作使得这对塔变得“优美”,则输出 YES;否则输出 NO。
你可以以任意大小写形式输出每个字母(YES、yes、Yes 均被视为肯定回答;NO、no、nO 均被视为否定回答)。
输入输出样例
输入#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.
在第一个测试用例中,你可以将第一座塔顶部的方块移动到第二座塔(参见第三张图片)。
在第二个测试用例中,你可以将第二座塔顶部的方块移动到第一座塔共 6 次。
在第三个测试用例中,这对塔已经是优美的。
输入解题思路,AI测评打分。不知道怎么写?