Statistics

Problem Statement for "SimplifiedDarts"

Problem Statement

You are playing a simplified version of darts. For each throw, you choose one of two distances from the target and throw the dart. If you hit the target from the short distance, you get 2 points, and if you hit it from the long distance, you get 3 points. You get no points for missing the target.

You get N throws, and you must get at least W points to win. You hit the target with probability P1 percent from the short distance, and with probability P2 percent from the long distance. Return the expected probability (as a percentage between 0 and 100) that you will win.

Definition

Class:
SimplifiedDarts
Method:
tryToWin
Parameters:
int, int, int, int
Returns:
double
Method signature:
double tryToWin(int W, int N, int P1, int P2)
(be sure your method is public)

Notes

  • Your return value must have an absolute or relative error less than 1e-9.

Constraints

  • W will be between 1 and 1000, inclusive.
  • N will be between 1 and 1000, inclusive.
  • P1 will be between 0 and 100, inclusive.
  • P2 will be between 0 and 100, inclusive.

Examples

  1. 5

    2

    50

    25

    Returns: 12.5

    You should make one throw from the short distance and one throw from the long. Both throws must be successful to win. The expected probability of winning is 0.5*0.25 = 12.5%.

  2. 6

    3

    90

    20

    Returns: 73.30000000000001

    You are a good short distance shooter. Make your first throw from the short distance. If you hit the target, make your next two throws from the short distance as well. If you miss the first throw, you need to make the next two throws from the long distance. The expected probability of winning is 0.9*(0.9*0.9) + 0.1*(0.2*0.2) = 73.3%.

  3. 30

    384

    3

    1

    Returns: 18.344490479047746

    You are a bad shooter, but you have many attempts.

  4. 999

    333

    0

    100

    Returns: 100.0

    You are an excellent 3-point shooter. The victory is yours.

  5. 1000

    333

    0

    100

    Returns: 0.0

    You are an excellent 3-point shooter, but it is impossible to get 1000 points with just 333 throws.

  6. 532

    479

    72

    7

    Returns: 99.99999999999952

  7. 803

    771

    26

    75

    Returns: 100.0

  8. 341

    332

    1

    62

    Returns: 100.0

  9. 978

    915

    62

    22

    Returns: 99.99999447808712

  10. 694

    122

    23

    1

    Returns: 0.0

  11. 246

    3

    19

    51

    Returns: 0.0

  12. 632

    567

    83

    17

    Returns: 100.0

  13. 826

    80

    62

    24

    Returns: 0.0

  14. 505

    774

    21

    8

    Returns: 3.235029605705033E-12

  15. 307

    851

    42

    82

    Returns: 100.0

  16. 29

    979

    63

    60

    Returns: 100.0

  17. 492

    731

    18

    45

    Returns: 100.0

  18. 294

    17

    12

    86

    Returns: 0.0

  19. 530

    724

    84

    2

    Returns: 100.0

  20. 291

    254

    71

    55

    Returns: 99.9999980074316

  21. 208

    456

    1

    60

    Returns: 100.0

  22. 782

    236

    60

    24

    Returns: 0.0

  23. 818

    547

    6

    25

    Returns: 5.963226361492138E-34

  24. 738

    288

    63

    51

    Returns: 8.23578546675441E-33

  25. 197

    275

    77

    23

    Returns: 100.0

  26. 845

    958

    9

    27

    Returns: 4.9180599012723905

  27. 57

    163

    14

    24

    Returns: 99.99772493742063

  28. 410

    730

    26

    3

    Returns: 10.806578868329625

  29. 762

    673

    5

    30

    Returns: 0.0010472478621256177

  30. 485

    687

    30

    8

    Returns: 0.14399494904573085

  31. 453

    584

    24

    29

    Returns: 95.84876025867963

  32. 839

    599

    62

    18

    Returns: 0.0021433240735887612

  33. 723

    394

    1

    61

    Returns: 49.492091127129875

  34. 428

    440

    18

    42

    Returns: 99.99826765735607

  35. 659

    337

    60

    70

    Returns: 97.31657990578955

  36. 204

    282

    31

    26

    Returns: 78.40843687510235

  37. 474

    377

    29

    48

    Returns: 99.23335949272146

  38. 62

    26

    31

    75

    Returns: 33.714411458790885

  39. 838

    436

    93

    22

    Returns: 0.47220630429819865

  40. 251

    512

    21

    3

    Returns: 2.7434051431279816

  41. 228

    182

    65

    16

    Returns: 77.42320991618868

  42. 359

    227

    55

    64

    Returns: 99.97734105092933

  43. 83

    797

    6

    2

    Returns: 82.97157145157963

  44. 810

    467

    24

    66

    Returns: 99.99021295368615

  45. 454

    350

    47

    45

    Returns: 74.3116072263093

  46. 842

    434

    68

    61

    Returns: 6.092580947939844

  47. 952

    888

    48

    27

    Returns: 0.050900483523618464

  48. 835

    444

    54

    60

    Returns: 12.030085470170029

  49. 780

    464

    67

    64

    Returns: 99.9826678126776

  50. 713

    796

    41

    14

    Returns: 1.5709819597507901

  51. 830

    310

    96

    86

    Returns: 5.043058938335629

  52. 711

    439

    81

    63

    Returns: 99.99570215526509

  53. 817

    363

    33

    70

    Returns: 1.6303222276235743

  54. 473

    313

    51

    48

    Returns: 20.748064663188952

  55. 167

    125

    51

    23

    Returns: 0.026493002744617068

  56. 107

    147

    24

    20

    Returns: 11.158850702419116

  57. 408

    491

    36

    18

    Returns: 0.649990007686892

  58. 643

    917

    29

    22

    Returns: 16.384821787152344

  59. 523

    691

    11

    28

    Returns: 94.7236522554947

  60. 385

    424

    51

    0

    Returns: 98.94685274798275

  61. 604

    351

    16

    57

    Returns: 43.972050199458536

  62. 49

    79

    41

    13

    Returns: 96.74635044609903

  63. 183

    144

    8

    45

    Returns: 76.3843752871948

  64. 233

    82

    64

    83

    Returns: 0.09248042950304801

  65. 217

    129

    81

    47

    Returns: 25.79414635080777

  66. 1000

    653

    53

    89

    Returns: 100.0

  67. 191

    131

    35

    48

    Returns: 45.63977244862386

  68. 1000

    407

    31

    99

    Returns: 100.0

  69. 237

    327

    8

    27

    Returns: 88.963246472822

  70. 505

    390

    61

    15

    Returns: 6.6497277648268085

  71. 268

    443

    28

    3

    Returns: 15.841662536644327

  72. 860

    522

    48

    54

    Returns: 34.28525732079538

  73. 754

    456

    37

    56

    Returns: 64.27179603173326

  74. 501

    516

    34

    31

    Returns: 26.56090640028942

  75. 241

    239

    10

    33

    Returns: 40.84383916005378

  76. 1000

    570

    31

    63

    Returns: 98.63669433956981

  77. 296

    102

    10

    87

    Returns: 0.047709075792224345

  78. 810

    510

    31

    52

    Returns: 35.176476623747675

  79. 1000

    595

    69

    59

    Returns: 93.13187049539495

  80. 336

    241

    76

    19

    Returns: 98.96621703634301

  81. 1

    1

    100

    100

    Returns: 100.0

  82. 1000

    1000

    50

    25

    Returns: 51.47945169449058

  83. 1

    5

    50

    50

    Returns: 96.875

  84. 30

    384

    3

    1

    Returns: 18.344490479047746

  85. 1000

    824

    32

    28

    Returns: 7.985531368406269E-13

  86. 53

    55

    3

    2

    Returns: 2.73920017493805E-15

  87. 274

    403

    11

    65

    Returns: 100.0

  88. 564

    876

    42

    91

    Returns: 100.0

  89. 1000

    500

    40

    30

    Returns: 3.409646828907625E-62


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: