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
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.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.50
Returns: 0
1
Returns: 68