ArmorUp
TCO17 Regional Wildcard · 2017-03-31 · by cgy4ever
Problem Statement
- 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.
You are given the
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.
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.
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.
100 100 2 Returns: 58.57864376269048
1000000000 987654321 1234 Returns: 1113069.7492973686
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.
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