Rock-Paper-Scissors Tournament

Interview

Time limit1sMemory limit256 MB

Summary
Count wins and losses for each player across all games, then print each player's win average w/(w+l) to three decimals, or - if the denominator is 0.
Level

Medium4 of 10

Topics
Simulation, Implementation, Math, Hash map
Solved
No attempts yet

Problem

Rock-Paper-Scissors is a game for two players, A and B, who each independently choose one of rock, paper, or scissors. Paper beats rock, scissors beats paper, and rock beats scissors. If both players choose the same thing, neither wins nor loses (a tie).

A tournament is held with nn players. Every player plays kk games of Rock-Paper-Scissors against each of the other players, for a total of k⋅n⋅(n−1)2\dfrac{k \cdot n \cdot (n-1)}{2} games.

Compute the win average of each player, defined as ww+l\dfrac{w}{w+l}, where ww is the number of games the player won and ll is the number of games the player lost (ties are not counted).

Print each win average rounded to three decimal places, rounding halves up. If a player's win average is undefined (that is, w+l=0w + l = 0), print - instead.

Input

The input consists of several test cases. The first line of each test case contains two integers nn and kk (1≤n≤1001 \le n \le 100, 1≤k≤1001 \le k \le 100). Then, for each game, one line follows in the format p1 m1 p2 m2: p1p_1 and p2p_2 (1≤p1,p2≤n1 \le p_1, p_2 \le n, p1≠p2p_1 \ne p_2) are the numbers of the two players, and m1m_1 and m2m_2 are their respective moves, each one of rock, scissors, or paper. Each test case contains exactly k⋅n⋅(n−1)2\dfrac{k \cdot n \cdot (n-1)}{2} game lines. A line containing a single 0 follows the last test case.

Output

For each test case, print the win average of player 1, player 2, and so on through player nn, one per line, each rounded to three decimal places. If a win average is undefined, print -. Print one empty line between the outputs of consecutive test cases.

Examples1

  1. Example 1

    Input
    2 4
    1 rock 2 paper
    1 scissors 2 paper
    1 rock 2 rock
    2 rock 1 scissors
    2 1
    1 rock 2 paper
    0
    
    Expected output
    0.333
    0.667
    
    0.000
    1.000