Statistics

Problem Statement for "ShootingGallery"

Problem Statement

You and your friend are at a shooting gallery, and your friend wants to make a bet that he can hit the target within a certain number of shots. You know that each time he takes a shot, there is an accuracy percent probability that he will hit the target. Return the maximal number of shots at which it is advantageous for you to take the bet. A number n is considered advantageous if the probability that your friend will hit the target in n or less shots is less than 50%.

Definition

Class:
ShootingGallery
Method:
profitableBet
Parameters:
int
Returns:
int
Method signature:
int profitableBet(int accuracy)
(be sure your method is public)

Notes

  • All shots are independent.
  • Hint: Try to calculate the probability that your friend will NOT hit the target in n or less shots.

Constraints

  • accuracy will be between 1 and 100, inclusive.

Examples

  1. 40

    Returns: 1

    In this case, he will hit the target in one shot with probability 0.4, and in two or less shots with probability 0.64.

  2. 20

    Returns: 3

    In one shot - 0.2. In two or less shots - 0.36. In three or less shots - 0.488. In four or less shots - 0.5904.

  3. 50

    Returns: 0

  4. 1

    Returns: 68

  5. 100

    Returns: 0

  6. 49

    Returns: 1

  7. 48

    Returns: 1

  8. 29

    Returns: 2

  9. 28

    Returns: 2

  10. 27

    Returns: 2

  11. 26

    Returns: 2

  12. 25

    Returns: 2

  13. 24

    Returns: 2

  14. 23

    Returns: 2

  15. 22

    Returns: 2

  16. 21

    Returns: 2

  17. 19

    Returns: 3

  18. 18

    Returns: 3

  19. 17

    Returns: 3

  20. 16

    Returns: 3

  21. 15

    Returns: 4

  22. 14

    Returns: 4

  23. 13

    Returns: 4

  24. 12

    Returns: 5

  25. 11

    Returns: 5

  26. 10

    Returns: 6

  27. 9

    Returns: 7

  28. 8

    Returns: 8

  29. 7

    Returns: 9

  30. 6

    Returns: 11

  31. 5

    Returns: 13

  32. 4

    Returns: 16

  33. 3

    Returns: 22

  34. 2

    Returns: 34

  35. 55

    Returns: 0

  36. 76

    Returns: 0

  37. 51

    Returns: 0

  38. 52

    Returns: 0

  39. 99

    Returns: 0

  40. 2

    Returns: 34

  41. 20

    Returns: 3

  42. 50

    Returns: 0


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: