1571 - The Battle of Inuyasha

Time Limit : 3 Second

Memory Limit : 128 MB

Submission: 3

Solved: 2

Description
    The Shikon Jewel(四魂之玉) is a powerful artifact that will grant great power to whomever attains it. Many people seek the Shikon Jewel – some for good, others for evil. You must use courage and strategy to defeat your enemies on the battlefield, or the Shikon Jewel will be forever lost to you.

                                                                                                                              ——《Inuyasha》

 

    “Inuyasha” is a Japanese comic about the Shikon Jewel, a group of people: Inuyasha, Kagome, Miroku and Sango are fighting with a bad role, Naraku, to prevent him from using Shikon Jewel for evil. And there exists some impressive roles, such as Sesshomaru, Koga and Kikyo,

everyone of them has great power and a brave heart to fight for the Jewel.

    The story of Inuyasha becomes a game, you can control a role to fight with computer on the battlefield. Of course, computer also has a role. Each role has some attacking skills, for example, Wind Scar(风之伤) and Hiraikotsu(飞来骨). The battlefield is a map with 3 rows and 4 columns, just like the picture below.


    At the beginning of the fight, each role has 100 HP(Health Point) and 100 MP(Mana Point). The first role is at cell(1, 0) and the second role is at cell(1, 3). Two roles can stay in a same cell.

In the fight, one role must use actions to defeat the other role. These actions are:

1.  moves

    MoveRight, means move to the right cell, for example, from cell (1, 1) to cell(1, 2);

    MoveLeft, for example, from cell(0, 3) to cell(0, 2);

    MoveUp, for example, from cell(1, 2) to cell(0, 2);

    MoveDown, for example, from cell(1, 2) to cell(2, 2);

    DoubleRight, for example, from cell(1, 2) to cell(3, 2);

    DoubleLeft, for example, from cell(2, 1) to cell(0, 1).

 

    Every move costs 0 MP, and note that roles can’t move out of the battlefield. For example, if you are at cell(0, 2) and want to MoveUp, you just stay at cell(0, 2), and if you are at cell(1, 2) and want to DoubleRight, you just move to cell(1, 3).

 

2.  Attacking Skills

    An attacking skills has a name, the damage caused to the other role(called DM), the mana cost for this skill(called EN) and the range of a skill. If you don’t have enough energy, you couldn’t use your skill.

    Let me illustrate the range of a skill. We can use a 3*3 grid to show the range of skill. The center square is where you are, the highlighted squares display which squares on the grid will be affected by this attacking skill. Look the picture below, it shows that Inuyasha has a skill called Wind Scar, it costs 50 points of MP to use the skill. If the other role is affected by Wind Scar, he/she will lose 50 points of HP.




3.  EnergyUp

    You can regenerate your energy in the battlefield, you just stay and increase your MP by 15 points. For example, if you have 50 points of MP and you choose EnergyUp as your action, you can increase your MP to 65 points. Note that your MP can’t exceed 100 points, that’s to say, if you have 90 points of MP and want to EnergyUp, you can increase your MP to 100 points, but not 105 points.

 

4.  Heal

    You can stay and cost 60 points of MP to increase your HP by 40 points. Note that your HP can’t exceed 100 points, but your HP can be less than 0.

 

5.  Guard

    You can stay and defend other role’s attack by 15 HP. For example, you are affected by other role’s attacking skill, and the skill can cause 50 HP of damage, if your action is guard, you will just lose 35 points of HP. Note that, if the damage of skill is less than 15 points of HP and you choose guard, you won’t increase your HP. The effect of guard will last until its corresponding action pair(I’ll mention it later) is end.

  

    The two role’s battle lasts many rounds until one of them have no strength to fight, that’s to say, HP is no more than 0.

    At each round, every role has 3 actions, called a combo. You can use the actions just mentioned to make a combo. When a round starts, each role will use their first actions, then second actions, then the third actions, called the first action pair, the second action pair and the third action pair, respectively.

    Pay attention to the sequence of these actions in an action pair, the priority of actions are: Guard > Moving > EnergyUp > Attacking Skills > Heal. If these two actions have the same priority, the first role goes first.

    After an action pair, if someone’s HP is no more than 0, the battle comes to result: the first role wins, the second role wins, or draw game. After each round, everyone’s MP will increase by 15 points, but if the battle is end, their MP won’t increase.

    Pay attention to this condition: now the first role have 25HP, his current action is Heal, and the second role’s action is an attacking skill with 50 points of DM. The second role goes first. If the first role was affected by the attacking skill, his HP will become: 25 – 50 + 40 = 15, not -25HP or 40HP or 0HP.

    Now, I’ll give you the skill of each role and the actions of each round, you should tell me the result of battle and the winner’s remain HP and MP when the battle ends.

Input
    The first line of input is an integer T, indicates the number of test cases.

    Then the first line of each test case contains three positive integers: N, S1, S2, indicating the number of rounds, attacking skills of player1, attacking skills of player2.

    After the first line, there are S1+S2 blocks, indicating these attacking skills, the first S1 blocks are player1’s skills, and the last S2 blocks are player2’s skills. Each block consists of 4 lines, the first line contains a string, indicating the skill’s name, and two positive integers DM and EN, indicating the skill’s damage cause and mana cost. The two to four lines are the range of the skill, ‘#’ indicates affected area, and ‘.’ indicates non-affected area.

    Then follows 6*n lines, every 6 lines indicates a round. The first 3 lines indicates the first role’s actions, the last 3 lines indicates the second role’s actions. Each line is either skill’s name or one of the follows: “MoveUp”, “MoveDown”, “MoveLeft”, “MoveRight”, “DoubleLeft”, “DoubleRight”, “Heal”, “EnergyUp”, “Guard”.

 

    The length of skill’s name is no more than 20, and it only contains alphabets.

    1 <= S1, S2 <= 5

    1 <= N <= 30

    0 <= DM, EN <= 100



    It’s guaranteed the test data is legal and the battle will have a result after N rounds.

 

Output
   In each test case, the output contains one line.

   You should first  print "Case #X: ", where X is the test case number (starting with 1).

If the first role wins, output “The first role wins.”(quote for clarify) and then output his remaining DM and EN, using a space to separate.

  If the second role wins, output “The second role wins.”(quote for clarify) and then output his remaining DM and EN, using a space to separate.

  If it’s a draw game, just output “Draw Game!”(quote for clarify).

 

sample input
2
2 3 1
BladeStrike 30 25
.#.
.#.
.#.
WindScar 50 50
...
.#.
###
BladeOfBlood 25 25
.#.
###
.#.
PoisonPowder 30 20
.#.
.#.
.#.
MoveRight
Guard
BladeOfBlood
MoveUp
MoveDown
MoveLeft
MoveRight
WindScar
BladeStrike
MoveDown
PoisonPowder
EnergyUp

1 2 1
CycloneDash 35 25
...
###
...
FistOfRage 50 45
...
.#.
###
WindTunnel 50 50
###
.#.
...
MoveRight
FistOfRage
FistOfRage
DoubleLeft
WindTunnel
WindTunnel
sample output
Case #1: The first role wins. 70 15
Case #2: Draw Game!
hint
    Large data input, scanf/printf is recommended.
source
Kangqi LUO
© 2015 HUST ACMICPC TEAM. All Right Reserved.