21488_BoardGameDice

2022-5-16 18:19| 发布者: Hocassian| 查看: 28| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505322095200-Problem List-采集的数据-后羿采集器.html

Pro.ID

21488

Title

Board Game Dice

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21488

AC

6

Submit

29

Ratio

20.69%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    hh is a Board Game hobbyist, he often plays Board Game such as Catan, Carcassonne, The Werewolves, A song of ice and fire with friends.

    To play the games, we need some dices, and these dices are very unusual. Maybe with eight or twelve sides.

    hh plays with N friends today (including himself). They'll choose one person to be the judge. But the problem is: there is only a M-sided dice. How to pick a judge with the dice, so that everyone has equal probability of being chosen (the probability should always be 1 / N)?

    hh has an idea here:

    1) Get  x

    Decide rolling the dice x times to make M x larger than or equal to N.

    2) Players choose sequences

    Each player chooses a sequence with x elements (1~M).

    For example, a 6-sides dice and x equal to 3, hh will gets sequence 4 5 6. Players' sequences should be different from each other.

    3) Pick the judge

    Roll the dice for x times, we can get a result sequence, if someone has the same sequence as the result, he will be the judge; otherwise, repeat 1)-3), until the judge is chosen.

    It's a bigger project, hh wants know the expected number of times we will need to throw dice to determine the judge.

    输入

    The first line is a number T ( 1 ≤ T ≤ 30 ), which represents the number of cases. The next T blocks following are the cases.

    Each case contains two integer N , M ( 2 ≤ N ≤ 109, 2 ≤ M ≤ 20 )

    输出

    Description

    hh is a Board Game hobbyist, he often plays Board Game such as Catan, Carcassonne, The Werewolves, A song of ice and fire with friends.

    To play the games, we need some dices, and these dices are very unusual. Maybe with eight or twelve sides.

    hh plays with N friends today (including himself). They'll choose one person to be the judge. But the problem is: there is only a M-sided dice. How to pick a judge with the dice, so that everyone has equal probability of being chosen (the probability should always be 1 / N)?

    hh has an idea here:

    1) Get  x

    Decide rolling the dice x times to make M x larger than or equal to N.

    2) Players choose sequences

    Each player chooses a sequence with x elements (1~M).

    For example, a 6-sides dice and x equal to 3, hh will gets sequence 4 5 6. Players' sequences should be different from each other.

    3) Pick the judge

    Roll the dice for x times, we can get a result sequence, if someone has the same sequence as the result, he will be the judge; otherwise, repeat 1)-3), until the judge is chosen.

    It's a bigger project, hh wants know the expected number of times we will need to throw dice to determine the judge.

    Input

    The first line is a number T ( 1 ≤ T ≤ 30 ), which represents the number of cases. The next T blocks following are the cases.

    Each case contains two integer N , M ( 2 ≤ N ≤ 109, 2 ≤ M ≤ 20 )

    Output

    For each case, output the number of case and expected number of throw as an irreducible fraction in the following form: "a/b" (as shown in the sample output)

    Sample Input

    2
    3 2
    9 3

    Sample Output

    Case 1: 8/3
    Case 2: 2/1

    Source

    样例输入

    2
    3 2
    9 3

    样例输出

    Case 1: 8/3
    Case 2: 2/1

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部