There is a two-player game on board ( rows, columns), with the following rules:
At the start of the game, a kangaroo game piece is placed on the bottom left square of the board.
Players alternate turns moving the kangaroo, and the first player moves first.
On the player's turn, they can either move the kangaroo some number of squares to the right, keep it in the same row, or they can move it to the leftmost square on the row above.
A player loses if they are unable to make a move.
Mio and Mai decided to play this game. Mio wants to know whether she can win a game before it even starts, if they play optimally, of course. After all, Mai is prone to cheating, so don't worry You are helping the good side.
You will be given a file, where in the first row there will be a number representing how many games they will be playing. In the following lines, there will be numbers, for row those will be , and , in that order. and represent the board size for game. The is information on who is the first player for game. For Mai plays first, whilst for Mio plays first.
For the described games, you need to answer how many wins will Mio have.
Click for FILE .
Guarantees:
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Solution:
I will label the first player as person A and the second one will be B .
Let see in which cases A will have a definite win.
That is when table has more than one column. A will just go to the rightmost field, so that B will always have to use the move in which the piece goes one-up and to the leftmost field. Eventually, it will be B 's turn in which piece will be placed at the up-right corner, from which it cannot be moved.
So basically, it seems that player A will mostly be the winner of the game. Special case tables, when B has a chance is one-column tables. With those tables, only valid move would be to move the piece in the neighboring upper field (which is always the leftmost and rightmost at the same time due to only one column). If the number of rows is odd number, player B wins, if not, player A wins.
This was the logical part, which is the most important one. Now, it is only required to make a proper input from file and to make few if statements.
The following part of code is provided with such if statements:
Click here to enlarge the image of code.
For the provided file for this problem, this variable solution at the end will be 2 5 4 0 4 .