#P7336. 1+1 Interactive Battle

    ID: 20534 Type: Default 1000ms 256MiB

1+1 Interactive Battle

1+1 Interactive Battle

This is an interactive two‐player game called 1+1. Two players, identified as a and b, each start with two single-digit numbers. Players take turns making a move. On a move the active player chooses one of his own numbers and one of the opponent’s numbers, adds them, and then replaces his chosen number with the ones digit of the sum. For example, if a player has a number 7 and the opponent has a number 5 then 7+5=12 and the ones digit is 2.

Special Configurations:

After every move, the following configurations are recognized (order does not matter):

  • Attack configurations:
    • 3 3 with attack degree 1
    • 5 3 (or 3 5) with attack degree 1
    • 6 1 (or 1 6) with attack degree 1
    • 9 1 (or 1 9) with attack degree 2
  • Defense configurations:
    • 5 1 (or 1 5) with defense degree 1
    • 5 5 with defense degree 2

Any combination not listed above is considered to have an attack or defense degree of 0.

Special Adjustment Rules:

If the defender (the player not moving) currently holds a defense configuration and the active player’s move results in an attack configuration (i.e. attack degree > 0), then:

  • If the attack degree is less than or equal to the defender’s defense degree, the move is nullified. Specifically:
    • If the defender’s defense degree is 1 (i.e. configuration 1 5), then the defender’s numbers are both changed to 1 (i.e. becomes 1 1).
    • If the defender’s defense degree is 2 (i.e. configuration 5 5), then the defender’s second number is changed to 1 (i.e. becomes 5 1), while the first number remains unchanged.

Victory Condition:

After a move is made (and before any special adjustments), if the active player’s attack degree is strictly greater than the defender’s defense degree, then the active player wins immediately and no adjustments are performed.

Input/Output and Game Protocol:

Your program acts as the first mover. It will receive the initial states and a sequence of moves. The players are labeled a and b. The moves are given in order (starting with player a). Each move is specified by two numbers: the index (1 or 2) of the number to use from the active player, and the index (1 or 2) of the opponent’s number to add.

The game is simulated as follows:

  1. Read the initial states of player a and b. Each state consists of two digits.
  2. Read an integer m denoting the number of moves.
  3. For each move in order:
    1. Let the active player choose his number and one of the opponent’s numbers as specified. Compute the new value as \( (x+y) \bmod 10 \).
    2. Temporarily update the active player’s state (only the chosen number is replaced).
    3. Determine the attack degree of the active player’s new state (if it matches one of the attack configurations) and the defense degree of the opponent’s state (if it matches one of the defense configurations).
    4. If the active player’s attack degree is greater than the opponent’s defense degree, output the active player’s label (a or b) and stop.
    5. If the opponent’s state is a defense configuration (defense degree > 0) and the active player’s new state is an attack configuration (attack degree > 0) but the attack degree is less than or equal to the defense degree, then the active player’s move is cancelled (his state reverts to before the move) and the opponent’s state is adjusted:
      • If defense degree is 1, the opponent’s state becomes 1 1.
      • If defense degree is 2, the opponent’s state becomes first_number 1 (i.e. the second digit is changed to 1).
    6. If neither condition applies, accept the move and update the active player’s state.
  4. If no move results in an immediate win, output draw after processing all moves.

Note: All sums are taken modulo 10 (i.e. only the ones digit is kept), and indices are 1-indexed.

inputFormat

The first two lines contain the initial states of player a and player b, respectively. Each line contains two space-separated digits.

The third line contains an integer m representing the number of moves.

The following m lines each contain two space-separated integers. In each line, the first integer is the index (1 or 2) of the active player’s number to use, and the second integer is the index (1 or 2) of the opponent’s number to add. Moves alternate between player a and player b, starting with a.

outputFormat

Output a single line containing either a or b if one of the players wins, or draw if no winning move occurs after all moves have been processed.

sample

1 3
2 4
1
1 1
a

</p>