CatAndRabbit
SRM 558 · 2012-06-05 · by lyrically
Problem Statement
There are some tiles in a row. Each of the tiles is colored white or black. You are given a
Cat and Rabbit take alternating turns. Cat plays first. In each turn, the following actions must be performed:
- First, the player must select a black tile and step on it.
- Then, the player must make some steps (as many as they want, but at least one). In each step, the player must select an adjacent white tile, move to that tile, and change its color to black.
Constraints
- tiles will contain between 1 and 50 characters, inclusive.
- Each character in tiles will be '.' or '#'.
Statement by TopCoder, Inc. — view the original on the archive.
"#.." Returns: "Cat"
In the first turn, Cat will select the leftmost tile and can move to the right twice. Then Rabbit has no legal move and loses.
".#." Returns: "Rabbit"
In the first turn, Cat must select the middle tile. Then, Cat can decide whether to step to the left or to the right. In the second turn, Rabbit will select the middle tile and then step in the opposite direction.
"###" Returns: "Rabbit"
Cat has no legal move at the beginning of the game.
"#..##.#" Returns: "Cat"
"..." Returns: "Rabbit"
Submissions are judged against all 103 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CatAndRabbit with a public method string getWinner(string tiles) · 103 test cases · 2 s / 256 MB per case