Блог пользователя _Evoiz_

Автор _Evoiz_, история, 6 лет назад, По-английски

what is the best way to solve this problem ? game theory? we have N*M empty grid and we have two players each player in his turn take an empty cell and put "X" in it game end when a player can make line with three "X" (like tik-tak-too game) players play optimally so who is the winier in this game?

  • Проголосовать: нравится
  • +15
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by _Evoiz_ (previous revision, new revision, compare).

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by _Evoiz_ (previous revision, new revision, compare).

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What are the constraints on n, m? If they are very small, then we can do masking to solve this problem.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Do diagonal lines also count?

»
6 лет назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

Edited: Sorry, I totally misunderstood problem.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Since the player wins when 3 X's are together, the below solution assumes that either of m or n is greater than or equal to 3.

Player 1 wins only when both m and n are odd. Else player two will win.

The logic is simple. Suppose that either of m or n is not odd. Hence player 2 can always mimic turn of player 1 and upon getting appropriate chance it can make the winning move.

Where as if both m and n are odd, player 1 will place first X in the center square of grid and then player 1 will mimic each turn of player 2 thus on getting appropriate chance player 1 will make the winning move.

Thus player 1wins if both m and n are odd else player 2 wins

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    i think it's work , thank you.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Sorry, how can the second player win if we have 4x4 grid and the first player starts the game marking by "X" the field (2,2) (here it doesn't matter whether 0-based or 1-based coordinates are)?

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      i think if n or m less than or equal to two then their is no winner . or we can say that if player didn't find any empty cell he will be lose and game over . so we can see if n or m less than 3 this is special case, other this if n or m is even player 2 will wine

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      if n or m is even then i can split the grid to two grid (n*m/2) or (n/2*m) and the second player make move like the first player

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        We can't split it independently, the halfs will affect each other. In case of 4x4 grid and first step (2,2) the second player can't reply symmetrically, otherwise he looses.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Assuming the grid is 3x3 (like the original tic-tac-toe), by your solution Player 1 is the winner, whereas when both playing optimally in original tic-tac-toe game (3x3 grid), the results are always end up in draws. It contradicts with your solution (I don't know the solution yet, though).

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      if the first player put "X" in the center of grid ,what ever player two put his "X" the first will can make a line with three "X" .

  • »
    »
    6 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    I didn't get, why if n is odd and m is even the second player wins. For example, if n = 3 and m = 4 then the first player can put X in cell (2, 2) (we suppose lines are numbered from 1 to 3 and columns from 1 to 4). Then the second player has to put in cell (2, 3), doesn't he? If he does, so the first player will win

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can you please provide link to the problem so that we can also learn

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    i am so sorry , their is no link because i write this problem and i didn't find a solution for it . i didn't see this problem in any other online judge before

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Quoting from this article. A 3-in-a-row game is a winning game for Player 1 if and only if N >= 3 and M >= 4 (number of row and column can be swapped). Otherwise, it's a draw game (3x3 or smaller grid).

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    it's not like tic-tak-too because the two players play with "X"

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      p1: put "X" in cell (2,2)(center);p2: put"X" in cell (1,1);p1: put"X" in cell(3,3) and p1 win

      • »
        »
        »
        »
        6 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Ah, I see. I'm sorry I misunderstood your problem thinking that thr X from Player 1 and 2 are different.