Unloaded Die
Time limit1sMemory limit512 MB
Given probabilities of the six faces of a loaded die, change one face's label so the expected value is exactly 3.5, minimizing the absolute label change.
- Level
Easy3 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
A six-sided die has its faces labeled 1 through 6. The die is fair if every face is equally likely to land face up, and loaded if it is not fair. For example, a die whose face marked 6 comes up twice as often as any other face is loaded.
The expected result of rolling a die is the average of the face labels, weighted by the probability that each face comes up. Every face of a fair die is equally likely, so its expected result is .
You are given a loaded die and you want to unload it so that it behaves more like a fair one. You can erase the number on one face and write a new number there. The new number does not have to be an integer and does not have to be positive. Pick the face and the new number so that:
- the expected result of rolling the die becomes exactly ;
- the difference between the old label and the new label on the face you change is as small as possible.
The expected result can always be brought to this way.
Input
The first line holds six space-separated nonnegative real numbers . Here is the probability that face , currently labeled with the number , comes up.
The six numbers sum to exactly , and each one is given as a decimal with at most six digits after the decimal point.
Output
Print on the first line the smallest possible absolute difference between the new label and the old label, rounded to exactly three digits after the decimal point. Round a value that is exactly halfway up.