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
100
Returns: 0
49
Returns: 1
48
Returns: 1
29
Returns: 2
28
Returns: 2
27
Returns: 2
26
Returns: 2
25
Returns: 2
24
Returns: 2
23
Returns: 2
22
Returns: 2
21
Returns: 2
19
Returns: 3
18
Returns: 3
17
Returns: 3
16
Returns: 3
15
Returns: 4
14
Returns: 4
13
Returns: 4
12
Returns: 5
11
Returns: 5
10
Returns: 6
9
Returns: 7
8
Returns: 8
7
Returns: 9
6
Returns: 11
5
Returns: 13
4
Returns: 16
3
Returns: 22
2
Returns: 34
55
Returns: 0
76
Returns: 0
51
Returns: 0
52
Returns: 0
99
Returns: 0
2
Returns: 34
20
Returns: 3
50
Returns: 0