TopcoderArchiveVisit Topcoder
TCO7 Sep 2017
Fun SRM 2017-09-10

ArmorUp

Problem statement, definition, constraints, and public examples.

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.

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

  1. 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.
  2. 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.
  3. 100
    100
    2
    Returns: 58.57864376269048
  4. 1000000000
    987654321
    1234
    Returns: 1113069.7492973686
Back to all problems