Statistics

Problem Statement for "RPSChamps"

Problem Statement

N people take part in a Rock-Paper-Scissors tournament. The purpose of the tournament is to assign every participant a distinct place from 1 to N.

The places are assigned by running a number of rounds of Rock-Paper-Scissors. In each round, each participant casts one of three figures - Rock, Paper, or Scissors - with equal probability. Rock beats Scissors, Paper beats Rock, and Scissors beats Paper. After all the participants have cast their figures, the round is replayed if one of the following occurred:

  • All participants cast the same figure.
  • Each of the three figures was cast at least once.

If the round is not replayed, then for every pair of participants who cast different figures, the one whose figure beat the other player's figure will take a higher place. Within each group of players who cast equal figures, an independent subtournament will be run using the same rules. Of course, if a group contains only one player, no rounds are needed to determine that player's placement within that group.

For example, consider a tournament between 5 players where the results of the first round are as follows:

  • Player 1 casts Rock
  • Player 2 casts Scissors
  • Player 3 casts Scissors
  • Player 4 casts Rock
  • Player 5 casts Scissors

The players will be divided into 2 groups: {P1, P4} and {P2, P3, P5}. An independent subtournament will be run for each group. Since Rock beats Scissors, the players from the first group will take overall places in the range 1-2 depending on the results of their subtournament, and players assigned to the second group will take places in the range 3-5 depending on the results of their subtournament.

Given N, the number of participants in the tournament, return the expected number of rounds.

Definition

Class:
RPSChamps
Method:
numberOfMoves
Parameters:
int
Returns:
double
Method signature:
double numberOfMoves(int N)
(be sure your method is public)

Notes

  • The returned value must have absolute or relative error less than 1E-9.
  • If a round is replayed one or more times, every replay is counted towards the total number of rounds for that tournament.

Constraints

  • N will be between 1 and 500, inclusive.

Examples

  1. 1

    Returns: 0.0

    Since there is only one participant, no rounds are needed to determine placement.

  2. 2

    Returns: 1.5

    There is a 1/3 probability of each round being replayed. When a round is not replayed, all places are immediately determined.

  3. 3

    Returns: 3.0

  4. 10

    Returns: 35.59012622220019

  5. 20

    Returns: 1201.2046591553308

  6. 50

    Returns: 2.1258780895391312E8

  7. 100

    Returns: 1.3552039578464264E17

  8. 200

    Returns: 5.509733035960696E34

  9. 473

    Returns: 6.51694834406221E82

  10. 500

    Returns: 3.70261258648865E87

  11. 321

    Returns: 1.1173079840475635E56

  12. 123

    Returns: 1.5209103288160166E21

  13. 444

    Returns: 5.097975758361231E77

  14. 499

    Returns: 2.4684083909924314E87

  15. 4

    Returns: 4.928571428571429

  16. 5

    Returns: 7.342857142857143

  17. 6

    Returns: 10.386635944700462

  18. 7

    Returns: 14.292165898617512

  19. 8

    Returns: 19.408371131027977

  20. 9

    Returns: 26.25243424268362

  21. 375

    Returns: 3.606624189509555E65

  22. 400

    Returns: 9.107147438266989E69

  23. 497

    Returns: 1.0970703959966359E87

  24. 197

    Returns: 1.6325134921365016E34


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: