JollyJumpers
SRM 376 · 2007-11-14 · by jmzero
Problem Statement
You are playing a board game called Jolly Jumpers. The game begins with some number of pawns on a 4x4 board. On each turn, you must either:
- Have one pawn jump over another pawn vertically. To do this, the jumping pawn must be vertically adjacent to the pawn it is to jump, with an empty space on the far side. The jumping pawn moves to the empty space, while the jumped pawn is removed from the game. Jumping a pawn scores two points.
- Move a pawn one space horizontally. The space it moves to must be empty. Moving a pawn means you lose one point.
You start the game with a score of zero points, and the goal of the game is to score as high as possible. You may stop moving at any time, including before your first move. The layout of the board will be given to you in the
For the layout given, return the maximum score you can achieve using any number of moves.
Constraints
- layout will contain 4 elements.
- Each element of layout will contain exactly 4 characters.
- Elements of layout will contain only '.' and '#' characters.
{
"....",
".#..",
"..#.",
"...."}
Returns: 1
Move either piece horizontally (-1 point), then jump vertically (+2 points).
{
"....",
"....",
"....",
"...."}
Returns: 0
Not the most exciting layout...
{
".#..",
".#..",
"..#.",
"...#"}
Returns: 4
{
"####",
"####",
"####",
"####"}
Returns: 0
You can't move outside the board, so there's no moves available.
{
"#...",
".##.",
"...#",
"...."}
Returns: 3
{
"#.#.",
"#...",
"....",
".#.#"}
Returns: 5
2-1+2-1+2-1+2=5
{
"#...",
"...#",
"....",
"...."}
Returns: 0
Moving is not worthwhile.
Submissions are judged against all 48 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class JollyJumpers with a public method int maxScore(vector<string> layout) · 48 test cases · 2 s / 256 MB per case