Statistics

Problem Statement for "FixedDiceGameDiv2"

Problem Statement

Alice and Bob are playing a game. Alice has an a-sided die. Bob has a b-sided die. (The faces of an n-sided die have numbers 1 through n written on them.)

The game is simple: Each player rolls their die, and the player who rolls a strictly larger number wins. (It is possible that neither player wins.)

You are given the ints a and b. The players already rolled their dice. You do not know what numbers they rolled, but you know that Alice won the game. Compute and return the expected value of the number Alice rolled.

Definition

Class:
FixedDiceGameDiv2
Method:
getExpectation
Parameters:
int, int
Returns:
double
Method signature:
double getExpectation(int a, int b)
(be sure your method is public)

Notes

  • Your return value must have absolute or relative error smaller than 1e-9.
  • The expected value can be seen as the average of many experiments. In our case, suppose that you folow a lot of games, and each time Alice wins, you write down her score. As you watch more and more games, the average of all numbers you have written down will converge to the expected value you should return.

Constraints

  • a and b will each be between 2 and 1000, inclusive.

Examples

  1. 2

    2

    Returns: 2.0

    Alice can only win if she rolls a 2 and Bob rolls a 1. Thus, if we know Alice wins, we know she rolled a 2.

  2. 4

    2

    Returns: 3.2

  3. 3

    3

    Returns: 2.6666666666666665

  4. 11

    13

    Returns: 7.999999999999999

  5. 6

    6

    Returns: 4.666666666666667

  6. 50

    50

    Returns: 34.0

  7. 2

    1000

    Returns: 2.0

  8. 1000

    2

    Returns: 501.2498748122179

  9. 1000

    1000

    Returns: 667.3333333333333

  10. 418

    382

    Returns: 278.40618101545294

  11. 573

    923

    Returns: 382.6666666666668

  12. 182

    39

    Returns: 101.10905349794261

  13. 294

    392

    Returns: 196.66666666666612

  14. 574

    964

    Returns: 383.3333333333333

  15. 192

    723

    Returns: 128.66666666666697

  16. 940

    382

    Returns: 558.1269205076807

  17. 483

    17

    Returns: 246.4746835443017

  18. 293

    420

    Returns: 195.99999999999997

  19. 572

    674

    Returns: 382.0000000000002

  20. 850

    878

    Returns: 567.3333333333334

  21. 681

    483

    Returns: 439.8580106302186

  22. 492

    549

    Returns: 328.66666666666663

  23. 207

    157

    Returns: 135.47656249999977

  24. 134

    323

    Returns: 89.99999999999999

  25. 948

    816

    Returns: 627.3246833487768

  26. 583

    404

    Returns: 375.3771353482258

  27. 603

    727

    Returns: 402.6666666666667

  28. 458

    3

    Returns: 230.4992690058504

  29. 182

    683

    Returns: 122.00000000000001

  30. 788

    468

    Returns: 495.262270400481

  31. 544

    66

    Returns: 288.8945478289269

  32. 648

    856

    Returns: 432.66666666666686

  33. 459

    600

    Returns: 306.6666666666666

  34. 497

    883

    Returns: 332.0000000000003

  35. 759

    40

    Returns: 390.15978334462284

  36. 855

    177

    Returns: 470.7959094865139

  37. 649

    11

    Returns: 327.9922239502304

  38. 249

    243

    Returns: 166.62729658792654

  39. 498

    470

    Returns: 332.1866666666661

  40. 866

    573

    Returns: 553.3724812895771

  41. 530

    341

    Returns: 337.5041782729804

  42. 239

    869

    Returns: 160.0

  43. 657

    99

    Returns: 353.32729269631477

  44. 321

    487

    Returns: 214.66666666666683

  45. 329

    323

    Returns: 219.97005988023966

  46. 786

    750

    Returns: 524.1550954120997

  47. 674

    477

    Returns: 435.20613026819996

  48. 994

    29

    Returns: 504.9642492339228

  49. 420

    457

    Returns: 280.66666666666674

  50. 44

    51

    Returns: 30.0

  51. 13

    796

    Returns: 9.333333333333334

  52. 700

    700

    Returns: 467.3333333333329

  53. 5

    7

    Returns: 4.0

  54. 6

    2

    Returns: 4.222222222222222

  55. 999

    499

    Returns: 611.1481975968048

  56. 10

    2

    Returns: 6.235294117647061

  57. 49

    48

    Returns: 33.333333333333336

  58. 99

    989

    Returns: 66.66666666666667


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: