KingdomAndDice
SRM 548 · 2012-06-05 · by fushar
Problem Statement
King Dengklek has been playing with the first die for a long time. Therefore, some of its labels were scratched off. The corresponding sides of the die are now empty. The second die still has all of its labels.
The current labels on the first die are given in the
In King Dengklek's favorite game, he takes one of the dice, his opponent takes the other, and they each roll the die they have. The one who throws a larger number is the winner. King Dengklek wants to fill in the missing labels on the first die. His goal is to fill them in such a way that his favorite game becomes as fair as possible.
When filling in the missing labels, King Dengklek wants to preserve the two properties mentioned above: first, each integer between 1 and X, inclusive, may only occur at most once on the two dice. Second, no other labels may be used. However, there is an exception to the second rule: King Dengklek is also allowed to use the label 0. Moreover, he may even use this label multiple times.
You are given the
Notes
- Your return value must have a relative or an absolute error of less than 1e-9.
- |x| denotes the the absolute value of x. For example, |3| = |-3| = 3.
Constraints
- firstDie and secondDie will contain the same number of elements, between 2 and 50, inclusive.
- X will be between 2*N and 1,000,000,000, inclusive, where N is the number of elements in firstDie.
- Each element of firstDie will be between 0 and X, inclusive.
- Each element of secondDie will be between 1 and X, inclusive.
- Each integer between 1 and X, inclusive, will occur at most once in firstDie and secondDie together.
Statement by TopCoder, Inc. — view the original on the archive.
{0, 2, 7, 0}
{6, 3, 8, 10}
12
Returns: 0.4375
One possible solution is to relabel the first die into {4, 2, 7, 11}. The probability of winning against the second die will be 7/16.
{0, 2, 7, 0}
{6, 3, 8, 10}
10
Returns: 0.375
One possible solution is to relabel the first die into {9, 2, 7, 5}. The probability of winning against the second die will be 3/8.
{0, 0}
{5, 8}
47
Returns: 0.5
One possible solution is to relabel the first die into {10, 0}.
{19, 50, 4}
{26, 100, 37}
1000
Returns: 0.2222222222222222
The first die does not have any missing labels.
{6371, 0, 6256, 1852, 0, 0, 6317, 3004, 5218, 9012}
{1557, 6318, 1560, 4519, 2012, 6316, 6315, 1559, 8215, 1561}
10000
Returns: 0.49
Submissions are judged against all 148 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class KingdomAndDice with a public method double newFairness(vector<int> firstDie, vector<int> secondDie, int X) · 148 test cases · 2 s / 256 MB per case