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:
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.
- 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 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.
Definition
- Class:
- ArmorUp
- Method:
- minimalDamage
- Parameters:
- int, int, int
- Returns:
- double
- Method signature:
- double minimalDamage(int maxHP, int currentHP, int k)
- (be sure your method is public)
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
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