CS: The Kangaroo Hops For Two

There is a two-player game on M × N M \times N board ( M M rows, N N columns), with the following rules:

  1. At the start of the game, a kangaroo game piece is placed on the bottom left square of the board.

  2. Players alternate turns moving the kangaroo, and the first player moves first.

  3. 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.

  4. 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 G G representing how many games they will be playing. In the following G G lines, there will be 3 3 numbers, for i th i^\text{th} row those will be M i M_i , N i N_i and P i P_i , in that order. M i M_i and N i N_i represent the board size for i th i^\text{th} game. The P i P_i is information on who is the first player for i th i^\text{th} game. For P i = 0 P_i = 0 Mai plays first, whilst for P i = 1 P_i = 1 Mio plays first.

For the G G described games, you need to answer how many wins will Mio have.

Click for FILE .

Guarantees:

  • For every i i : P i { 0 , 1 } P_i \in \{ 0, 1 \} .
  • For every i i : 1 M i , N i < 2 32 1 \le M_i , N_i < 2^{32} .

Inspiration .

If there are questions for this problem, ask here .


The answer is 25404.

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.

1 solution

Milan Milanic
Jul 2, 2016

Solution:

I will label the first player as person A A and the second one will be B B .

Let see in which cases A A will have a definite win.

That is when table has more than one column. A A will just go to the rightmost field, so that B 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 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 A will mostly be the winner of the game. Special case tables, when B 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 B wins, if not, player A 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 25404 25 404 .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...