Search code examples
mathprobability

Programming question(death battle) on probability


In a crossover fantasy universe, houin kyoma is up in a battle against powerful monster nomu that can kill him in a single blow. However being a brilliant scientist kyoma found a way to pause time for exactly M seconds. Each second, kyoma attacks nomu with certain power, which will reduce his health points by that exact power Initially nomu had H health points. Nomu dies when his health points reach 0, Normally kyoma performs normal attack with power A. Besides from kyomas brilliance, luck plays a major role in events of this universe. Kyoma luck L is defined as probability of performing a super attack. A super attack increases power of normal attack by C. Given this information calculate and print the probability that kyoma kills nomu and survives. If kyoma dies print RIP.

Input format First line is integer T denoting number test cases. Each test case consist of single line with space separated number A H L1 L2 M C. Where luck L is defined as L1/L2. Other number are, as described above

Output Print probability that kyoma kills nomu in form p1/p2 where p1<=p2 and gcd(p1,p2)=1. If impossible, print RIP without quotes

Example input 1 10 33 7 10 3 2 Output 98/125

How the probability comes to 98/125?


Solution

  • You have 3 seconds ==> 3 attacks.

    Monster has 33 health points.

    Normal attack does 10 damage.

    Super attack does 12 damage.

    ==> In order to kill the monster you need to get lucky at least twice out of three attacks.

    The probability of super attack is 7/10, the probability of standard attack is 3/10.

    Let's check the variants: If first attack is not lucky, the other 2 must be lucky. If first attack is lucky, only one of the remaining 2 must be lucky.

    ==> Probability to kill the monster = 3/10*7/10*7/10+7/10*(3/10*7/10+7/10) = 98/125