VENOM - Touch of Venom
Sometimes you have to try fighting even though you know that your enemy is very powerful than you. Your hero with initial health H is about to fight against a venomous enemy who has a poisonous value of P. The enemy's poison deals i*P damage at it's ith attacking chance(i>=1). The hero dies when his health becomes <=0. After enemy's attack, if the hero survives, he heals himself with a health of A by using his skills. Then the enemy gets the chance again and the cycle continues till the hero dies. Find the survival time of the hero. You can safely assume that the hero is mortal.
Initial Health(H) = 10, Poison (P) = 2, Heal value(A) = 1
At time 1, enemy does 1*2 damage reducing the hero's health to 8
At time 2, hero heals himself by 1 increasing his health to 9
At time 3, enemy does 2*2 damage reducing the hero's health to 5
At time 4, hero heals himself by 1 increasing his health to 6
At time 5, enemy does 3*2 damage and kill the hero.
The hero survived 5 units of time.
The first line consists of an integer t, the number of test cases. For each test case there is a line with 3 integers H, P and A.
For each test case, find the survival time of the hero.
3 7 2
81 4 1
87 8 4
Happy to get AC? Now write a bruteforce and see if your solution gives same result for [spoiler]. I don't understand why my AC one doesn't. I love cegprakash's problems but this one wrecked the day for me :(
TLE with ios_base.Use scanf/printf...
Pure math and scanf/printf :)
did using [spoiler]
did it using [spoiler] :PLast edit: 2017-08-02 12:47:17
Nice application of Quadratic sequence. :) <3
carefull with data type, it might make u get tle :)
Last edit: 2016-04-09 18:54:52
AC but 1.23 seconds with scanf and 0.8 with a rather fast input function .. :/ Used inequations, not sure what I can do to decrease time, other than fast I/O .. Wonder how people got O(1) .. Anyways, cegprakash always brings good questions ..Last edit: 2015-12-28 05:23:55