Connection Status:
Competition Arena > ArmorUp
TCO17 Regional Wildcard · 2017-03-31 · by cgy4ever · Math
Class Name: ArmorUp
Return Type: double
Method Name: minimalDamage
Arg Types: (int, int, int)
Problem Statement

Problem Statement

In most Multiplayer Online Battle Arena (MOBA) games, you control a character and you use it to attack other characters. In these games we usually have the following concepts:

  • HP (hit points, or health points): A real number that describes the health of a character. The larger the value, the healthier the character. If HP drops to zero or a negative value, the character dies.
  • Damage: A positive real number. If a character has no armor and receives some damage, its HP is decreased by the amount of damage it received.
  • Armor: A real number between 0 and 100, inclusive. The armor value of a character is the percentage of damage that gets prevented.
For example, suppose that an enemy character has HP = 100 and armor = 0. If you deal them 10 damage, their HP will decrease to 100 - 10 = 90. In the same situation, if their armor were 20, then 20% of the damage would be prevented. Thus, the same attack would only decrease the enemy's HP to 100 - 0.8 * 10 = 92.

You are given the ints maxHP, currentHP, and k. You are fighting an opponent. The opponent's maximum amount of HP is maxHP and their current amount of HP is currentHP. You want to kill the opponent in k hits, each dealing the same amount D of damage.

The enemy character has a special trait called "Armor Up". At any moment, their armor corresponds to the amount of health they are missing, with 1 armor corresponding to 2% of maximum health. For example, if their maximum HP is 1000 and their current HP is 999, their current armor will be 0.05.

Compute and return the smallest value of D such that k consecutive hits, each dealing D damage, are enough to kill the given enemy character.

Notes

  • Your answer will be considered correct if its absolute or relative error does not exceed 10^(-6).

Constraints

  • maxHP will be between 1 and 1,000,000,000, inclusive.
  • currentHP will be between 1 and maxHP, inclusive.
  • k will be between 1 and 1,000,000,000, inclusive.
Examples
0)
100
100
1
Returns: 100.0

The enemy has full HP so the armor is 0 and we want to kill it after 1 hit, so the amount of damage needed is 100.

1)
100
20
1
Returns: 33.333333333333336

This enemy is already missing 80% of their health. Hence, their current armor is 40, which means that only 60% of the damage will actually cause loss of health. In order to kill them in a single hit, we need to deal at least (100/3) = 33.33333 damage. This will reduce the opponent's HP by exactly (100/3) * 60% = 20.

2)
100
100
2
Returns: 58.57864376269048
3)
1000000000
987654321
1234
Returns: 1113069.7492973686
4)
1
1
1
Returns: 1.0

Submissions are judged against all 113 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ArmorUp with a public method double minimalDamage(int maxHP, int currentHP, int k) · 113 test cases · 2 s / 256 MB per case

Submitting as anonymous