Pistol Pete, the neighborhood game dealer, has offered to let you play his newest game. Pete's going to let you throw a dart at his wall containing several targets. Depending on what target you hit, you will win a fabulous prize!
You've been practicing a game like this lately, and you figure it's right up your alley. You will hit the target you aim at with prob percent probability. When you miss the target you aim at, you will hit either of the adjacent targets with equal probability. Since the targets are arranged in a circular fashion, if you miss target 0, then you will either hit target 1 or target n-1, where n is the total number of targets. See example 0 for clarification.
Pete has given you a int payout, in which the i-th element corresponds to the payout of hitting target i. You will also be given prob, the percent probability your dart will hit the target you aim for. The total number of targets is equal to the number of elements in payout. Given this information, return a double with the average payout that you will get from Pete if you play optimally.
|Method signature:||double bestScore(int payout, int prob)|
|(be sure your method is public)|
|-||A return value with either an absolute or relative error of less than 1.0e-9 is considered correct.|
|-||payout will contain between 3 and 50 elements, inclusive.|
|-||Each element of payout will be between 0 and 100, inclusive.|
|-||prob will be between 0 and 100, inclusive.|
|In this case, you have three options:
Of the three options, the best score is 45, and so we return it.
- Aim at 10: Score = 10(0.8) + 50(0.1) + 40(0.1) = 17.0
- Aim at 40: Score = 40(0.8) + 10(0.1) + 50(0.1) = 38.0
- Aim at 50: Score = 50(0.8) + 40(0.1) + 10(0.1) = 45.0
|This time, you don't throw as well. In this case, it is best to aim for the 50, scoring 50(0.61) + 40(0.195) + 10(0.195) = 40.25.|
|Sometimes missing can be a good thing.|