401486: GYM100482 F Magician Wars

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Magician Warstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Two powerful magicians “The king of fire” and “The hero of ice” are fighting each other to conquer the world. The winner will be the one who is the smarter and…a bit more successful.

The fight between two greatest magicians involves a lot of strategy because magicians can cast only limited amount of spells during each moment of time.

You support the king of fire just because the summer has just ended and you want to swim in the sea and to play volleyball in the beach… Ah, these good summer days! It may be possible again with the power of fire!

Each magician is characterized by hp (health points), atk (the strength of the attack), def (the defence abilities). Each spell is one of the following types:

  • “Heal x”, which changes hp to min(current_hp + x;10);
  • “Atk x”, which changes atk to max(current_atk;x);
  • “Def x”, which changes def to max(current_def;x);
  • “HIT!”, which deals damage to the opponent which equals max(0;attacking_atk - defending_def);

Opponent loses the dealt damage points from his hp. If player’s hp becomes less than or equal to 0 he is considered dead and his opponent is a winner.

Each player starts with hp = 10, atk = 0, def = 0. Luckily the king of fire moves first. It may increase our chances!

Each player has a sequence of 10 spells. He can reuse the same spell again. During the first turn a magician can use the first 5 spells, during the second - the first 6 spells and so on…During the turn a magician can cast only one spell.

Note: assume that both magicians are very wise and don’t make mistakes, i.e. they play optimally well. It means that a magician tries to minimize the number of turns if it is possible to win. If it is impossible to win, then a magician tries to maximize the number of turns.

Note: it is guaranteed that the winner exists and the game ends in at most 12 turns (that’s it, at most 6 turns for one player).

Input

The first line contains the number of test cases T (0 ≤ T ≤ 20). The first 10 lines of each test case contain the spells of the king of fire (“Heal x”, “Atk x”, “Def x”, “HIT!”), 0 ≤ x ≤ 5. The other 10 lines of each test case contain the spells of the hero of ice (“Heal x”, “Atk x”, “Def x”, “HIT!”), 0 ≤ x ≤ 5.

Output

For each test case output one line containing “Case #tc: status turn”, where tc is the number of the test case (starting from 1), status is “win” or “lose” (“win” if the king of fire wins, “lose” otherwise), turn is the turn in which the final hit was made.

ExamplesInput
1
Atk 5
HIT!
HIT!
HIT!
HIT!
HIT!
HIT!
HIT!
HIT!
HIT!
Def 3
Def 2
Def 2
Def 2
Def 2
Def 2
Def 2
Def 2
Def 2
Def 2
Output
Case #1: win 11

加入题单

上一题 下一题 算法标签: