编程介的小学生 2016-12-26 12:15 采纳率: 20.5%
浏览 828
已采纳

Procrastination

Description

Once upon a time, there were two graduate students that were best friends. During their short breaks from research (usually, not longer than several hours), the two students liked to play the game of Procrastination.

The game of Procrastination is for two players (black and white), who take turns moving. The game involves removing cubes from towers. Each cube is either black or white. At the start of the game, these cubes are arranged into 4 towers: each tower is a stack of several cubes. On a player’s turn, he can remove any cube that matches his color (the white player removes only white cubes, and the black player only removes black cubes). All the cubes above the chosen cube are also removed from the tower, irrespective of color. For example, suppose a tower is composed of the following cubes (from bottom to top): black, white, black, white. Then, if black removes the bottom-most black cube, he removes the entire tower, black can also take the 3rd cube, removing the 4th cube with it. If white removes the 2nd cube, then only one black cube will remain, white can also take the 4th cube. If a player cannot remove any cubes, he loses.

Having already been trained in the intricacies of the game during their undergraduate years, the two students learned to play the game perfectly, i.e., if a player had a winning strategy, then that player would win the game. However, at some time, they discovered that, for most starting configurations, one of the players has the winning strategy irrespective of which player moves first. They called a configuration a W-configuration if white has a winning strategy irrespective of who moves first, and a B-configuration if black has a winning strategy irrespective of who moves first.

Moreover, the friends noted that some partial configurations are at least as favorable for one player as other configurations. A partial configuration C is defined as a set of 3 towers, note that a partial configuration C together with a 4th tower T forms a complete game configuration, which we denote as (C, T). A formal definition of the notion “at least as favorable”, is as follows. A partial configuration C1 (composed of 3 towers) is at least as favorable for white as another partial configuration C2 (also composed of 3 towers) if and only if for any 4th tower T, if (C2, T) is a W-configuration then (C1, T) is also a W-configuration. In other words, there does not exist a 4th tower T such that (C1, T) is not a W-configuration and (C2, T) is a W-configuration.

Given two partial configurations C1 and C2, you are to check whether C1 is at least as favorable for white as the partial configuration C2.

Input

The first line of the input contains an integer, the number of test cases. A test case includes one line with Test N, where N is the current test case number followed by eight lines, specifying the two partial configurations C1 and C2 in this order. Each configuration is specified by four lines.

The first line of the partial configuration contains three numbers: n1, n2, n3 denoting the heights of the three towers of the partial configuration (0 ≤ n1, n2, n3 ≤ 50). The second line contains n1 letters (B or W) separated by spaces describing the first tower. The third line contains n2 letters separated by spaces describing the second tower. The fourth line contains n3 letters separated by spaces describing the third tower. A letter W denotes a white cube and the letter B denotes a black cube. Each tower is described in the bottom-to-top order.

Output

For each test case, print on a separate line the test case number and Yes if C1 is at least as favorable for white as the partial configuration C2, and No otherwise.

Sample Input

2
Test 1
3 3 1
W B B
W B W
B
3 3 3
B W W
B W W
W B B
Test 2
3 3 2
W B B
W B W
B B
3 3 3
B W W
B W W
W B B
Sample Output

Test 1: Yes
Test 2: No

  • 写回答

1条回答 默认 最新

  • 当作看不见 2016-12-26 12:29
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?