No.23 技の選択
タグ : / 解いたユーザー数 284
作問者 :
nmnmnmnmnmnmnm
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
You want to defeat an enemy whose initial HP is H.
The enemy is defeated when its HP becomes 0 or less.
There are two ways to attack: a normal attack and a special move.
A normal attack deals A damage per attack.
A normal attack always hits.
A special move deals D damage per attack.
However, the probability that a special move hits is 2/3.
With probability 1/3, a special move deals 0 damage.
You choose attacks so as to minimize the expected number of attacks
until the enemy is finally defeated.
What is the expected number of attacks until the enemy is defeated?
Input
H A D
The enemy's HP H, the damage A of a normal attack, and the damage D of a special move are given on one line, separated by single-byte spaces.
$1 \le H,A,D \le 10000 $
Output
Output the answer as a decimal. An error of up to 0.01 in absolute or relative terms is allowed.
Sample
Sample 1
Input
10 10 20
Output
1
One normal attack defeats the enemy for certain.
Sample 2
Input
38 10 14
Output
4
The enemy can be defeated with 4 normal attacks without using the special move.
At the shortest, it can also be defeated with 3 special moves, but since the hit rate is 2/3, attacking only with special moves gives an expected value of 4.5 attacks.
With 0 normal attacks, the expected value using only special moves from the remaining HP of 38 is 4.5 attacks. (4.5 attacks in total)
With 1 normal attack, the expected value using only special moves from the remaining HP of 28 is 3 attacks. (4 attacks in total)
With 2 normal attacks, the expected value using only special moves from the remaining HP of 18 is also 3 attacks. (5 attacks in total)
With 3 normal attacks, the expected value using only special moves from the remaining HP of 8 is also 1.5 attacks. (4.5 attacks in total)
In this case, the minimum expected value is 4 attacks.
Sample 3
Input
49 7 17
Output
4.5
The enemy can be defeated with an expected 4.5 attacks using only special moves. Since 17×3=51≥49, 3 hits are required, which takes 3÷(2/3)=4.5 attacks. Mixing in normal attacks increases the expected value in every situation.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。