Statistics

Problem Statement for "ArmorUp"

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

  5. 1

    1

    1

    Returns: 1.0

  6. 65660050

    59

    424146325

    Returns: 2.7700973737054824E-7

  7. 35665

    5491

    873366

    Returns: 0.01169549611048426

  8. 9

    3

    852893

    Returns: 6.071425642240058E-6

  9. 350421119

    63476

    3186

    Returns: 39.84322019545382

  10. 21916892

    88

    58177111

    Returns: 3.0269801829518883E-6

  11. 865639

    79

    592149

    Returns: 2.668125427602863E-4

  12. 977692452

    20414

    713

    Returns: 57.261673456520064

  13. 439046715

    9290414

    77382874

    Returns: 0.23761031583878767

  14. 30820

    862

    1641524

    Returns: 0.0010358247273245524

  15. 989593

    6

    391557

    Returns: 3.064671070163172E-5

  16. 492962

    84

    26561

    Returns: 0.0063245242358589415

  17. 441714815

    5004

    1048952

    Returns: 0.009540868171939998

  18. 332587774

    8156124

    891148

    Returns: 18.083914631795864

  19. 3489609

    536

    56

    Returns: 19.141360884042015

  20. 9076718

    786

    74041

    Returns: 0.021230561247743474

  21. 6472773

    4736

    46075

    Returns: 0.20550268796685844

  22. 48150

    5

    82480447

    Returns: 1.2123032577804338E-7

  23. 97212195

    68484129

    6843566

    Returns: 15.14982942645526

  24. 780319

    595

    57786444

    Returns: 2.058516899894336E-5

  25. 66457236

    4275396

    6336555

    Returns: 1.307808080059636

  26. 803213

    2603

    1239446

    Returns: 0.004193472405530141

  27. 70834

    609

    92

    Returns: 13.18192908557455

  28. 582718469

    217131103

    1

    Returns: 3.163752494011244E8

  29. 837318

    9014

    87

    Returns: 206.09826176404644

  30. 2211412

    5295

    7659815

    Returns: 0.0013808873569427504

  31. 54129465

    3118320

    94583798

    Returns: 0.06410836145515852

  32. 15

    7

    4

    Returns: 2.7392123837132445

  33. 9859524

    5642

    87427

    Returns: 0.12903076453120033

  34. 9679146

    642390

    448

    Returns: 2776.458867245393

  35. 5360

    9

    5

    Returns: 3.5963775942545517

  36. 3752

    833

    7949

    Returns: 0.189274259480257

  37. 97067287

    9003

    951420508

    Returns: 1.8923768771106353E-5

  38. 46388

    11

    72

    Returns: 0.30551882999532953

  39. 22104318

    730

    200874

    Returns: 0.0072681178887155085

  40. 7277055

    75553

    2

    Returns: 74969.73046114591

  41. 618889

    76

    570461159

    Returns: 2.664592482215511E-7

  42. 52257490

    62194

    9

    Returns: 13811.758277230841

  43. 495668256

    82

    98

    Returns: 1.673469215826394

  44. 703833

    69661

    343002

    Returns: 0.3873184283225659

  45. 694820225

    49500

    5286

    Returns: 18.728050065162016

  46. 7357

    3371

    57

    Returns: 97.05033077381736

  47. 339038782

    18

    694272

    Returns: 5.186911362597968E-5

  48. 91951448

    271771

    721889

    Returns: 0.7518334937858633

  49. 8205876

    4358

    449558583

    Returns: 1.9383185920318624E-5

  50. 428591790

    86334

    4

    Returns: 43161.56619193431

  51. 771511417

    454764

    4443

    Returns: 204.65000818687307

  52. 8

    4

    6996491

    Returns: 9.272421763739658E-7

  53. 18997859

    1652547

    1967

    Returns: 1611.1367228395939

  54. 89156865

    58

    65820629

    Returns: 1.7619152770098623E-6

  55. 8027600

    533405

    877918

    Returns: 1.1764912665186422

  56. 43700680

    55558

    416464243

    Returns: 2.666424826980318E-4

  57. 611956699

    63

    221291

    Returns: 5.693442537002547E-4

  58. 71

    10

    940

    Returns: 0.01990417661010646

  59. 781464288

    75410486

    4

    Returns: 3.558382630646648E7

  60. 13233

    262

    89

    Returns: 5.829471760545919

  61. 672852701

    95335

    261812

    Returns: 0.7282190843046006

  62. 27568935

    690

    53

    Returns: 26.037403865686095

  63. 1723163

    8

    6

    Returns: 2.6666594447752656

  64. 8704

    1

    22049

    Returns: 9.070185080872761E-5

  65. 34981

    1641

    8

    Returns: 399.77153677254654

  66. 441520

    38332

    26966

    Returns: 2.726279586375977

  67. 91419033

    272760

    4

    Returns: 136126.25108156673

  68. 1985093

    654002

    87

    Returns: 12974.0540450406

  69. 5784459

    2888

    54

    Returns: 106.93577598424507

  70. 298015641

    911

    3263

    Returns: 0.5583810130616995

  71. 52693721

    1459

    6

    Returns: 486.32547847644133

  72. 844

    5

    24590515

    Returns: 4.0546111179651234E-7

  73. 688426

    54

    120075796

    Returns: 8.994357667546637E-7

  74. 318196

    28

    5

    Returns: 11.199408704471637

  75. 1425800

    182723

    2

    Returns: 166847.38762877954

  76. 20200

    6

    120

    Returns: 0.09998502772767814

  77. 363783151

    3892

    871588

    Returns: 0.008930765624995285

  78. 476157

    5861

    71985233

    Returns: 1.6184486420045552E-4

  79. 4736175

    3765267

    79288057

    Returns: 0.06988922767454664

  80. 21791676

    34271

    7352352

    Returns: 0.009315134193881747

  81. 428906508

    566644

    2042876

    Returns: 0.5543851356066147

  82. 824925562

    8669399

    76081220

    Returns: 0.226709294295516

  83. 515260

    200

    707378

    Returns: 5.653587733744914E-4

  84. 79206

    3

    575218655

    Returns: 1.0429248131771374E-8

  85. 2033

    39

    66

    Returns: 1.1704569122119868

  86. 6876757

    1015

    50776

    Returns: 0.03997656792304949

  87. 66708173

    88

    8293588

    Returns: 2.1225868154006733E-5

  88. 1887511

    739

    672637

    Returns: 0.002196891820594349

  89. 2970

    153

    381509094

    Returns: 7.821013836561974E-7

  90. 686855054

    70252565

    39

    Returns: 3425844.3225824353

  91. 48412907

    20792

    4663

    Returns: 8.915949189352473

  92. 279347

    8

    70

    Returns: 0.2285681089388929

  93. 9976018

    57184

    955195948

    Returns: 1.1939059033938548E-4

  94. 3560

    3

    10

    Returns: 0.5997220740468645

  95. 47138

    7

    3812323

    Returns: 3.6720249649846437E-6

  96. 34205304

    973683

    362040620

    Returns: 0.005303728929581197

  97. 28919

    3430

    854797687

    Returns: 7.583937100985594E-6

  98. 4996964

    99

    194

    Returns: 1.0206083940639523

  99. 57120172

    8832018

    3065923

    Returns: 5.357162836267196

  100. 4443431

    754209

    1

    Returns: 1289537.425092542

  101. 7047824

    8923

    89939

    Returns: 0.19829787165495816

  102. 1516388

    385705

    42115

    Returns: 16.319529174177053

  103. 296030316

    66710

    7711

    Returns: 17.300605277447854

  104. 726475

    7549

    746

    Returns: 20.13403677062598

  105. 920824759

    58

    526259594

    Returns: 2.0446416981734217E-7

  106. 1000000000

    1000000000

    1000000000

    Returns: 1.3862944125975218

  107. 1000000000

    1000000000

    1

    Returns: 1.0E9

  108. 1000000000

    1

    1000000000

    Returns: 0.0

  109. 1000000000

    1

    1

    Returns: 1.9999999979999998

  110. 1

    1

    1000000000

    Returns: 1.3862944125975218E-9

  111. 1

    1

    1

    Returns: 1.0

  112. 10000000

    10000

    1000000000

    Returns: 1.999067578140057E-5

  113. 1000000000

    987654321

    1000000000

    Returns: 1.373910318847038


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: