Shuttle game(translated by:LydiaCCC)

Shuttle game(translated by:LydiaCCC)

Farmer John's (FJ) cow, Bessie, recently gets addicted to checkers, so she asks FJ to teach her.
The checkerboard is 2*N+1 cells long, 1 cell wide, and the cells are numbered from 1 to 2*N+1 from left to right.
From the very beginning, N cells on the left are for the white, and N cells on the right are for the black. The middle cell is a blank space.
White can only move right, and black can only move left.
It is not allowed to go to a cell with a chess piece in it or go out of the checkerboard.
As a cow, Bessie knows nothing about board games so FJ starts with the basics.
He asked Bessie to move the chess pieces M times according to the following rules.
1. If a chess piece can skip an adjacent piece in different color and jump to the blank space, let it jump.
2. If no chess piece satisfies rule 1 and when a certain piece moves one step to the blank space, the chess pieces on both sides of the space have the same color after the move, move it. (It will fail to satisfy the rule 2 if there is only one chess piece on both sides of the blank space.)
3. If no chess piece satisfies the rules above, choose a chess piece randomly and move one step.
If there are more than one chess piece satisfying the rules, then move the chess piece with the smallest location number. For instance, if the chess pieces on both sides of the space can be moved according to the rules, it is required to move the left one, which is the one with the smaller location number.
Please help Bessie move the chess pieces and show FJ the final checkerboard.
Given a line of two integers, N and M. 1 < = N < = 10, 1 < = M < = 1000.
Output a line of 2*N+1 uppercase, indicating the chess pieces in each cell after M steps. W, B, S respectively represents white, black and space.

Sample
Input:

2 4

Output:

SBWWB

Explanation:
Initial checkerboard:

WWSBB

The checkerboard in the following 4 steps:

WSWBB
WBWSB
WBSWB
SBWWB

Special thanks: this is translated selflessly by LydiaCCC, who did not want to be named.

信息

难度
9
分类
(无)
标签
递交数
6
已通过
5
通过率
83%
上传者