No.3318 Pouring Egg on Customers
タグ : / 解いたユーザー数 10
作問者 :
Andrew8128
/ テスター :
ゆにたりー卿
DeltaStruct
kazuppa
のらら
Rice_tawara459
👑 Problem Statement
Iwai Seijin plans to work part-time at an okonomiyaki restaurant for at most $N$ days starting now.
Initially, his skill at cooking okonomiyaki is $X$, and he has $0$ yen.
Each day, he chooses one of the following two actions.
- Attend training: His skill increases by $Y$, and he earns $P$ yen as the daily wage for the training period.
-
Perform regular duties:
He earns $Q$ yen as the daily wage. However, with probability $ \frac{1}{\text{skill}} $, he pours egg on a customer.
If he pours egg on a customer, he chooses one of the following.
- Pay $R$ yen to serve the customer a complimentary lemon sour and cover up the incident (his money may become negative in this case).
- Do not cover it up; the manager finds out, and he is fired that same day.
The job ends when $N$ days have passed or when he is fired.
Iwai Seijin chooses his actions so as to maximize the expected value of his money at the time the job ends.
Find the expected value of his money when the job ends.
You are given $T$ test cases. Find the answer for each of them.
Constraints
All input values are integers
$1 \leq T \leq 300$
$1 \leq N \leq 10^{12}$
$1 \leq X, Y \leq 100$
$1 \leq P \leq Q \leq 10^5$
$1 \leq R \leq 10^5$
Input
The input is given from standard input in the following format, where $\mathrm{case}_i$ denotes the $i$-th test case.
$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$
Each test case is given in the following format.
$N$ $X\ Y$ $P\ Q\ R$
Output
Output $T$ lines.
On the $i$-th line, output the expected value of his money at the end of the job for the $i$-th test case.
Your answer is judged correct if the relative error is at most $10^{-8}$.
Sample
Sample
Input
5 1 1 1 1 2 10000 2 3 1 1 2 10000 2 3 1 1 2 1 3000 1 1 800 1000 200 1000000000000 100 100 100000 100000 100000
Output
2.0000000000 3.3333333333 3.6666666667 2978490.9090909091 100000000000000000.0000000000
In the 1st test case, Iwai Seijin's skill is $1$, so performing regular duties makes him pour egg on a customer with 100% probability; nevertheless, it is optimal to perform regular duties, pour egg on the customer, and get fired.
In the 2nd test case, it is optimal to perform regular duties on both day 1 and day 2.
With probability $ \frac{2}{3} $, he does not pour egg on a customer on day 1, and in this case Iwai Seijin's final money is $4$ yen.
With probability $ \frac{1}{3} $, he pours egg on a customer on day 1; in this case it is optimal for Iwai Seijin to get fired without covering it up, and his final money is $2$ yen.
Therefore, the answer is $ \frac{2}{3} \times 4 + \frac{1}{3} \times 2 = \frac{10}{3} $.
In the 3rd test case, it is optimal to perform regular duties on both day 1 and day 2.
With probability $ \frac{2}{3} $, he does not pour egg on a customer on day 1, and in this case Iwai Seijin's final money is $4$ yen.
With probability $ \frac{1}{3} $, he pours egg on a customer on day 1; in this case it is optimal for Iwai Seijin to pay $1$ yen and cover it up, and his final money is $3$ yen.
Therefore, the answer is $ \frac{2}{3} \times 4 + \frac{1}{3} \times 3 = \frac{11}{3} $.
Note that, as this test case illustrates, the sum of $N$ over the test cases is not necessarily at most $10^{12}$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。