#P8369. The Stripe Game
The Stripe Game
The Stripe Game
The Stripe Game is a two‐player impartial game played on a 1D board (or strip) composed of p consecutive squares. There are three types of colored stripes available: red, green, and blue. Each stripe is a rectangular tile of size:
- Red stripe: \(c\times1\)
- Green stripe: \(z\times1\)
- Blue stripe: \(n\times1\)
Both players have an unlimited supply of each type of stripe. The board is a \(p\times1\) rectangle (i.e. it has \(p\) cells of size \(1\times1\)). Players take turns placing a stripe onto the board subject to the following rules:
- The stripe must lie completely within the board.
- The stripe cannot overlap any previously placed stripe (even partially).
- The stripe must be aligned with the boundaries of the cells.
The first player who cannot make a move loses the game. The question is: does the first player always have a winning strategy regardless of how the opponent plays?
Your task is to write a program that:
- Reads the three stripe sizes and at least one board size \(p\) (there can be several boards).
- For each board, determines if the first player (the starting player) is guaranteed a win.
- Outputs the results.</p>
Game Theory Note: This is a combinatorial game that can be solved using the Sprague-Grundy theorem. For a board (or free segment) of length \(L\), let the Grundy value \(G(L)\) be defined as:
\[ G(L) = \text{mex} \Big\{ G(i) \oplus G(L - r - i) \;\big|\; r \in \{c, z, n\}, \; 0 \le i \le L - r \Big\} \]If \(L < \min(c, z, n)\) then no move is possible and \(G(L)=0\). The first player has a winning strategy if and only if \(G(p)\neq0\).
inputFormat
The input begins with a single line containing three positive integers \(c\), \(z\), and \(n\), representing the stripe sizes (red, green, and blue respectively). The next line contains a positive integer \(T\) representing the number of board queries. Each of the following \(T\) lines contains a positive integer \(p\) representing the board length.
Example:
2 3 4 3 1 5 7
outputFormat
For each board query, output a single line with either
Win
if the first player has a winning strategy for that board orLose
otherwise.Example Output:
Lose Win Win
sample
2 3 4 3 1 5 7
</p>Lose
Win Win