#abc350e. E - Toward 0
E - Toward 0
Score: points
问题陈述
给定一个整数 。你可以执行以下两种类型的操作:
- 支付 日元将 替换为 。
- 支付 日元掷一个骰子(一对骰子),骰子显示的整数在 到 之间,包括 和 ,概率相等。设 为骰子的结果,并将 替换为 。
这里, 表示小于或等于 的最大整数。例如, 和 。
确定在 变为 之前,通过最优选择操作支付的最小预期成本。每次操作中骰子的结果独立于其他掷骰,并且可以在观察到前一次操作的结果后做出操作的选择。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given an integer . You can perform the following two types of operations:
- Pay yen to replace with .
- Pay yen to roll a die (dice) that shows an integer between and , inclusive, with equal probability. Let be the outcome of the die, and replace with .
Here, denotes the greatest integer less than or equal to . For example, and .
Determine the minimum expected cost paid before becomes when optimally choosing operations.
The outcome of the die in each operation is independent of other rolls, and the choice of operation can be made after observing the results of the previous operations.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Your output will be considered correct if the absolute or relative error from the true answer is at most .
Sample Input 1
3 2 10 20
Sample Output 1
20.000000000000000
The available operations are as follows:
- Pay yen. Replace with .
- Pay yen. Roll a die. Let be the outcome, and replace with .
The optimal strategy is to perform the first operation twice.
Sample Input 2
3 2 20 20
Sample Output 2
32.000000000000000
The available operations are as follows:
- Pay yen. Replace with .
- Pay yen. Roll a die. Let be the outcome, and replace with .
The optimal strategy is as follows:
- First, perform the second operation to roll the die.
- If the outcome is or greater, then becomes .
- If the outcome is or , then becomes . Now, perform the first operation to make .
- If the outcome is , restart from the beginning.
Sample Input 3
314159265358979323 4 223606797 173205080
Sample Output 3
6418410657.7408381