-->
当前位置:首页 > 题库

PROGRAMMING:Unloaded die

Luz5年前 (2021-05-10)题库552
Consider a six-sided die, with sides labeled 1 through 6. We say the die is fair if each of its sides
is equally likely to be face up after a roll. We say the die is loaded if it isn’t fair. For example, if
the side marked 6 is twice as likely to come up as than any other side, we are dealing with a loaded
die.
For any die, define the expected result of rolling the die to be equal to the average of the values of
the sides, weighted by the probability of those sides coming up. For example, all six sides of a fair die
are equally likely to come up, and thus the expected result of rolling it is (1+2+3+4+5+6)/6 = 3.5.
You are given a loaded die, and you would like to unload it to make it more closely resemble a
fair die. To do so, you can erase the number on one of the sides, and replace it with a new number
which does not need to be an integer or even positive. You want to do so in such a way that
• The expected result of rolling the die is 3.5, just like a fair die.
• The difference between the old label and the new label on the side you change is as small as
possible.
Consider a six sided mold with side markings 1 to 6. We say that if each edge is equally likely to face after a roll, then the mold is fair. We said that if it's not fair, the mold will be installed. To test if the side marked 6 is twice as likely to appear as any other side, we are working on a loaded die. For any die, the expected result of rolling die is defined to be equal to the value of the average edge, weighted according to the probability of these edges. For example, all six aspects of a fair mold are equally possible, so the expected result of rolling it is (123456) / 6 = 3.5. You get a loaded mold, and you want to remove it to make it closer to a fair mold. To do this, you can delete the number on one of the sides and replace it with a new number, which does not need to be an integer or even a positive number. You want to do it so that
·The expected result of rolling die is 3.5, just like a fair die.
·The difference bets between the old tag and the new tag are as small as possible on the side you change.
###Input format:
The input consists of a single line containing six space-separated nonnegative real numbers v1 . . . v6,
where vi represents the probability that side i (currently labeled by the number i) is rolled.
It is guaranteed that the given numbers will sum to 1.
The input consists of a single line containing a non negative real number v1.v6 separated by six spaces, where VI is the probability that side I (marked by the number I) will be scrolled. Ensure that the sum of the given number will be 1.
###Output format:
Print, on a single line, the absolute value of the difference between the new label and old label,
rounded and displayed to exactly three decimal places.
Print, in one line, the absolute value of the difference between the new and old labels, rounded and displayed to the exact three decimal places.
###Input example:
Here is a set of inputs. For example:
```in
0.16666 0.16667 0.16667 0.16666 0.16667 0.16667
```
###Output example:
The corresponding output is given here. For example:
```out
zero
```







answer:If there is no answer, please comment