310185: CF1795A. Two Towers

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Two Towers

题意翻译

### 简述题意 有 $a,b$ 两座由红蓝色方块垒成的塔,其中 $a$ 的高度为 $n$ ; $b$ 的高度为 $m$ ,用 `R` 代表红色;用`B`代表蓝色。 你可以多次把其中一座顶端的方块移到另一座的顶端(可以不移动)。问有没有一种方法可以使两座塔中均没有连续的同颜色方块。 ### 输入输出 多组测试数据,对于每一组数据: 输入三行: 第一行有两个整数,分别为 $n$ 和 $m$ 。 第二行和第三行为两个字符串,分别为塔 $a$ 和塔 $b$ 。 输出一行: 若答案为正确,可以输出`YES`、`yes`或`Yes`,若答案为错误,可以输出`NO`、`no`或`nO`。

题目描述

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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1795A/69c3335e48895bcb4c761995acd0b1c64b9e8d07.png) 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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1795A/1c4aa5e98141199029dbc159f3efac85b139c1b9.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1795A/e96b9925d26bf52f3d8e10b859d46a71421db524.png)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.

输出格式


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).

输入输出样例

输入样例 #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.

Input

题意翻译

### 简述题意 有 $a,b$ 两座由红蓝色方块垒成的塔,其中 $a$ 的高度为 $n$ ; $b$ 的高度为 $m$ ,用 `R` 代表红色;用`B`代表蓝色。 你可以多次把其中一座顶端的方块移到另一座的顶端(可以不移动)。问有没有一种方法可以使两座塔中均没有连续的同颜色方块。 ### 输入输出 多组测试数据,对于每一组数据: 输入三行: 第一行有两个整数,分别为 $n$ 和 $m$ 。 第二行和第三行为两个字符串,分别为塔 $a$ 和塔 $b$ 。 输出一行: 若答案为正确,可以输出`YES`、`yes`或`Yes`,若答案为错误,可以输出`NO`、`no`或`nO`。

Output

题目大意:有两个由红蓝色方块堆叠成的塔,分别用字符串表示,其中`R`代表红色方块,`B`代表蓝色方块。可以通过多次移动,把任一塔顶的方块移到另一塔顶部,问是否可以使两座塔都不出现连续的同颜色方块。

输入输出数据格式:
- 输入:
- 第一行:一个整数 \( t \)(测试用例的数量,\( 1 \le t \le 1000 \))
- 每个测试用例包含三行:
- 第一行:两个整数 \( n \) 和 \( m \)(第一个塔和第二个塔的方块数,\( 1 \le n, m \le 20 \))
- 第二行:一个长度为 \( n \) 的字符串,表示第一个塔的方块颜色
- 第三行:一个长度为 \( m \) 的字符串,表示第二个塔的方块颜色
- 输出:
- 每个测试用例输出一行,如果可以使两座塔都满足条件,输出 `YES`,否则输出 `NO`。接受大小写不敏感的 `YES`/`yes`/`Yes` 或 `NO`/`no`/`nO`。题目大意:有两个由红蓝色方块堆叠成的塔,分别用字符串表示,其中`R`代表红色方块,`B`代表蓝色方块。可以通过多次移动,把任一塔顶的方块移到另一塔顶部,问是否可以使两座塔都不出现连续的同颜色方块。 输入输出数据格式: - 输入: - 第一行:一个整数 \( t \)(测试用例的数量,\( 1 \le t \le 1000 \)) - 每个测试用例包含三行: - 第一行:两个整数 \( n \) 和 \( m \)(第一个塔和第二个塔的方块数,\( 1 \le n, m \le 20 \)) - 第二行:一个长度为 \( n \) 的字符串,表示第一个塔的方块颜色 - 第三行:一个长度为 \( m \) 的字符串,表示第二个塔的方块颜色 - 输出: - 每个测试用例输出一行,如果可以使两座塔都满足条件,输出 `YES`,否则输出 `NO`。接受大小写不敏感的 `YES`/`yes`/`Yes` 或 `NO`/`no`/`nO`。

加入题单

算法标签: