B. The Modcrab

Codeforces
IDCF903B
Time1000ms
Memory256MB
Difficulty
greedyimplementation
English · Original
Chinese · Translation
Formal · Original
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has _h_2 health points and an attack power of _a_2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle. Vova's character has _h_1 health points and an attack power of _a_1. Also he has a large supply of healing potions, each of which increases his current amount of health points by _c_1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that _c_1 > _a_2. The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by _a_1) or drink a healing potion (it increases Vova's health by _c_1; **Vova's health can exceed _h_1**). Then, **if the battle is not over yet**, the Modcrab attacks Vova, reducing his health by _a_2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack. Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases. Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win. ## Input The first line contains three integers _h_1, _a_1, _c_1 (1 ≤ _h_1, _a_1 ≤ 100, 2 ≤ _c_1 ≤ 100) — Vova's health, Vova's attack power and the healing power of a potion. The second line contains two integers _h_2, _a_2 (1 ≤ _h_2 ≤ 100, 1 ≤ _a_2 < _c_1) — the Modcrab's health and his attack power. ## Output In the first line print one integer _n_ denoting the minimum number of phases required to win the battle. Then print _n_ lines. _i_\-th line must be equal to _HEAL_ if Vova drinks a potion in _i_\-th phase, or _STRIKE_ if he attacks the Modcrab. The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action. If there are multiple optimal solutions, print any of them. [samples] ## Note In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win. In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.
Vova 再次玩一款电脑游戏,这次是一款 RPG。在游戏中,Vova 的角色接到了一个任务:击败可怕的怪物 Modcrab。 在游戏两小时后,Vova 找到了这个怪物并分析了它的战术。Modcrab 拥有 #cf_span[h2] 点生命值和 #cf_span[a2] 点攻击强度。了解这些信息后,Vova 决定购买大量强力治疗药水并为战斗做准备。 Vova 的角色拥有 #cf_span[h1] 点生命值和 #cf_span[a1] 点攻击强度。此外,他拥有大量治疗药水,每瓶药水在 Vova 饮用后会将其当前生命值增加 #cf_span[c1]。所有药水都完全相同。保证 #cf_span[c1 > a2]。 战斗由多个阶段组成。在每个阶段开始时,Vova 可以选择攻击怪物(从而将其生命值减少 #cf_span[a1])或饮用一瓶治疗药水(将其生命值增加 #cf_span[c1];*Vova 的生命值可以超过 #cf_span[h1]*)。然后,*如果战斗尚未结束*,Modcrab 会攻击 Vova,将其生命值减少 #cf_span[a2]。当 Vova 或 Modcrab 的生命值降至 #cf_span[0] 或更低时,战斗结束。战斗可能在某个阶段中途结束,即在 Vova 攻击之后。 当然,Vova 希望赢得战斗,但他也希望尽可能快地完成。因此,他希望制定一个策略,使得在最少的阶段数内赢得战斗。 帮助 Vova 制定策略!你可以假设 Vova 永远不会耗尽治疗药水,并且他总能获胜。 第一行包含三个整数 #cf_span[h1], #cf_span[a1], #cf_span[c1](#cf_span[1 ≤ h1, a1 ≤ 100],#cf_span[2 ≤ c1 ≤ 100])——分别表示 Vova 的生命值、攻击强度和药水的治疗强度。 第二行包含两个整数 #cf_span[h2], #cf_span[a2](#cf_span[1 ≤ h2 ≤ 100],#cf_span[1 ≤ a2 < c1])——分别表示 Modcrab 的生命值和攻击强度。 第一行输出一个整数 #cf_span[n],表示赢得战斗所需的最少阶段数。 然后输出 #cf_span[n] 行。第 #cf_span[i] 行必须为 _HEAL_,表示在第 #cf_span[i] 阶段 Vova 饮用了药水;或为 _STRIKE_,表示他在该阶段攻击了 Modcrab。 策略必须有效:Vova 的角色在击败 Modcrab 前不能被击败,且在 Vova 最后一次行动后,怪物的生命值必须为 #cf_span[0] 或更低。 如果有多个最优解,输出任意一个即可。 在第一个示例中,Vova 的角色必须在第一次攻击前或后进行治疗。否则,他的生命值将在 #cf_span[2] 个阶段后降为零,而他需要 #cf_span[3] 次攻击才能获胜。 在第二个示例中,无需治疗,两次攻击足以将怪物生命值降至零,并以 #cf_span[6] 点生命值获胜。 ## Input 第一行包含三个整数 #cf_span[h1], #cf_span[a1], #cf_span[c1](#cf_span[1 ≤ h1, a1 ≤ 100],#cf_span[2 ≤ c1 ≤ 100])——Vova 的生命值、攻击强度和药水的治疗强度。第二行包含两个整数 #cf_span[h2], #cf_span[a2](#cf_span[1 ≤ h2 ≤ 100],#cf_span[1 ≤ a2 < c1])——Modcrab 的生命值和攻击强度。 ## Output 第一行输出一个整数 #cf_span[n],表示赢得战斗所需的最少阶段数。然后输出 #cf_span[n] 行。第 #cf_span[i] 行必须为 _HEAL_,表示在第 #cf_span[i] 阶段 Vova 饮用了药水;或为 _STRIKE_,表示他在该阶段攻击了 Modcrab。策略必须有效:Vova 的角色在击败 Modcrab 前不能被击败,且在 Vova 最后一次行动后,怪物的生命值必须为 #cf_span[0] 或更低。如果有多个最优解,输出任意一个即可。 [samples] ## Note 在第一个示例中,Vova 的角色必须在第一次攻击前或后进行治疗。否则,他的生命值将在 #cf_span[2] 个阶段后降为零,而他需要 #cf_span[3] 次攻击才能获胜。在第二个示例中,无需治疗,两次攻击足以将怪物生命值降至零,并以 #cf_span[6] 点生命值获胜。
**Definitions** Let $ h_1, a_1, c_1 \in \mathbb{Z}^+ $ denote Vova’s initial health, attack power, and healing power per potion, respectively. Let $ h_2, a_2 \in \mathbb{Z}^+ $ denote Modcrab’s health and attack power, respectively, with $ c_1 > a_2 $. Let $ n \in \mathbb{Z}^+ $ be the number of phases. Let $ s_i \in \{\text{STRIKE}, \text{HEAL}\} $ denote Vova’s action in phase $ i $. Let $ H_i \in \mathbb{Z} $ denote Vova’s health at the start of phase $ i $, with $ H_1 = h_1 $. Let $ M_i \in \mathbb{Z} $ denote Modcrab’s health at the start of phase $ i $, with $ M_1 = h_2 $. **Constraints** 1. $ 1 \leq h_1, a_1 \leq 100 $, $ 2 \leq c_1 \leq 100 $, $ 1 \leq h_2 \leq 100 $, $ 1 \leq a_2 < c_1 $. 2. For each phase $ i $: - If $ s_i = \text{STRIKE} $: $ M_{i+1} = M_i - a_1 $, and $ H_{i+1} = H_i - a_2 $ (if $ M_{i+1} > 0 $). - If $ s_i = \text{HEAL} $: $ H_{i+1} = H_i + c_1 $, and $ M_{i+1} = M_i $ (if $ M_i > 0 $). 3. Battle ends when $ M_k \leq 0 $ for some $ k \leq n $, and $ H_i > 0 $ for all $ i \leq k $. 4. $ M_{n+1} \leq 0 $, and $ H_i > 0 $ for all $ i \in \{1, \dots, n\} $. **Objective** Minimize $ n $, the number of phases, and output a sequence $ s_1, s_2, \dots, s_n $ satisfying the above.
Samples
Input #1
10 6 100
17 5
Output #1
4
STRIKE
HEAL
STRIKE
STRIKE
Input #2
11 6 100
12 5
Output #2
2
STRIKE
STRIKE
API Response (JSON)
{
  "problem": {
    "name": "B. The Modcrab",
    "description": {
      "content": "Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF903B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.\n\nAfter two hours of playing the game Vova has tracked ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Vova 再次玩一款电脑游戏,这次是一款 RPG。在游戏中,Vova 的角色接到了一个任务:击败可怕的怪物 Modcrab。\n\n在游戏两小时后,Vova 找到了这个怪物并分析了它的战术。Modcrab 拥有 #cf_span[h2] 点生命值和 #cf_span[a2] 点攻击强度。了解这些信息后,Vova 决定购买大量强力治疗药水并为战斗做准备。\n\nVova 的角色拥有 #cf_span[h1]...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ h_1, a_1, c_1 \\in \\mathbb{Z}^+ $ denote Vova’s initial health, attack power, and healing power per potion, respectively.  \nLet $ h_2, a_2 \\in \\mathbb{Z}^+ $ denote Modcrab’s he...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments