#P8700. [蓝桥杯 2019 国 B] 解谜游戏
[蓝桥杯 2019 国 B] 解谜游戏
Background

Problem Description
Xiaoming is playing a puzzle game. The puzzle consists of plastic sticks: yellow sticks, red sticks, and green sticks (later we use Y for yellow, R for red, and G for green). Initially, these sticks are arranged into three rings as shown in the picture above: the outer ring has sticks, the middle ring has sticks, and the inner ring has sticks.
Xiaoming can perform three kinds of operations:
- Rotate all three rings clockwise by one unit. For example, suppose the outer ring from the o’clock position clockwise is
YRYGRYGRGGGG, the middle ring isRGRGGRRY, and the inner ring isGGGR. After one clockwise rotation, the outer, middle, and inner rings becomeGYRYGRYGRGGG,YRGRGGRR, andRGGG, respectively. - Rotate all three rings counterclockwise by one unit. For example, suppose the outer ring from the o’clock position clockwise is
YRYGRYGRGGGG, the middle ring isRGRGGRRY, and the inner ring isGGGR. After one counterclockwise rotation, the outer, middle, and inner rings becomeRYGRYGRGGGGY,GRGGRRYR, andGGRG, respectively. - Perform a cyclic shift of the sticks at the o’clock position of the three rings. Specifically: the outer-ring stick at o’clock moves to the inner ring at o’clock, the inner-ring stick at o’clock moves to the middle ring at o’clock, and the middle-ring stick at o’clock moves to the outer ring at o’clock. For example, suppose the outer ring from the o’clock position clockwise is
YRYGRYGRGGGG, the middle ring isRGRGGRRY, and the inner ring isGGGR. After one cyclic shift, the outer, middle, and inner rings becomeRRYGRYGRGGGG,GGRGGRRY, andYGGR, respectively.
Xiaoming’s goal is to move all green sticks to the outer ring, all red sticks to the middle ring, and all yellow sticks to the inner ring. Given the initial state, determine whether Xiaoming can achieve the goal.
Input Format
The first line contains an integer , the number of test cases. .
Each test case contains lines:
The first line contains uppercase letters, representing the colors of the outer ring clockwise starting from the o’clock position.
The second line contains uppercase letters, representing the colors of the middle ring clockwise starting from the o’clock position.
The third line contains uppercase letters, representing the colors of the inner ring clockwise starting from the o’clock position.
Output Format
For each test case, output one line YES or NO, indicating whether Xiaoming can achieve the goal.
2
GYGGGGGGGGGG
RGRRRRRR
YRYY
YGGGRRRRGGGY
YGGGRRRR
YGGG
YES
NO
Hint
Lanqiao Cup 2019 National Contest B Group, Problem H.
Translated by ChatGPT 5