At the end of a popular television game show, contestants spin large wheels with various numbers on them to determine who wins the big prize.
Adjacent to each wheel is an arrow, used to indicate the resulting value when the wheel stops spinning.
Each contestant has their own wheel, possibly with a different set of numbers.
Each wheel is "fair", meaning that when a wheel with K numbers is spun, there is a 1/K chance that the wheel will stop on any given value.
Successive spins of the same wheel are independent.
Each contestant will spin their own wheel one or two times.
If they spin once, their score is simply the value indicated by the arrow.
If they choose to spin twice, their score is the sum of the values from their two spins,
but if their total score is greater than the largest value on their wheel, they are eliminated.
Each contestant can wait to see the result of their first spin before deciding if they want to spin a second time.
Whoever ends up with the highest score wins the big prize, and the others go home empty handed.
If multiple players have the same highest score, the player who went first among them will be declared the winner.
The contestants complete their turn (one or two spins) in a pre-determined order.
This gives the later contestants the advantage of knowing the previous contestants' scores,
helping them decide if they want to spin their wheel a second time.
You are the first player, and want to optimize your probability of winning the game.
Write a method to determine, for each value on your wheel, if you should stop if you got that value
on your first spin or if you should spin a second time.
Assume that the players following you will also play with a strategy that will optimize their own probability of winning.
If a player is guaranteed to lose after their first spin, they will always spin again just for fun.
You will be given the contestants' wheels as a String[] wheels,
where each element is a space-separated list of integers giving the various values on one player's wheel.
The number of elements in wheel indicates the number of contestants,
and the elements are given in the order that the players will take their turns.
The first element in wheels is your wheel, and the last element is the last player's wheel.
Return all the values on your wheel that you should stop with as a int[], in ascending order without duplicates.
|