Question

Death Battle Problem Description In a crossover fantasy universe, Houin Kyoma is up in a battle...

Death Battle

Problem Description

In a crossover fantasy universe, Houin Kyoma is up in a battle against a 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 has H Health Points. Nomu dies when his Health Points reach 0. Normally Kyoma performs Normal Attack with power A. Besides from Kyoma’s brilliance, luck plays a major role in events of this universe. Kyoma’s 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”.

Constraints

0 < T <= 50

1 <= A, H, C, L1, L2 <= 1000

1 <= M <= 20.

L1<=L2

Input Format

First line is integer T denoting number of test cases.

Each test case consist of single line with space separated numbers A H L1 L2 M C. Where luck L is defined as L1/L2. Other numbers 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.

Timeout

1

Explanation

Example 1

Input

2

10 33 7 10 3 2

10 999 7 10 3 2

Output

98/125

RIP

Homework Answers

Answer #1

Complete code in C++:-

#include <bits/stdc++.h>

using namespace std;

// For finding the factorial of a number 'a'
long long int fact(long long int a)
{
   long long int x = 1;
   while(a > 0)
   {
       x *= a;
       a--;
   }
   return x;
}

// For finding gcd of two numbers 'a', 'b'
long long int gcd(long long int a, long long int b)
{
   if(b == 0)
       return a;
   return gcd(b, a%b);
}

// Main function
int main(void)
{
   long long int a, h, l1, l2, m, c, t, p1, p2;

   // Teking user input for test cases.
   cout << "Input" << '\n';
   cin >> t;
   while(t--)
   {
       p1 = 0;
       p2 = 0;

       // Taking user input to process for each test case.
       cin >> a >> h >> l1 >> l2 >> m >> c;
       long long int temp = ceil((double)(h - a*m)/c);
       if(temp <= 0)
       {
           cout << 1 << "/" << 1;
       }
       else if(temp > m)
       {
           cout << "RIP";
       }
       else
       {
           p2 = pow(l2, m);
           while(temp <= m)
           {
               long long int ways = fact(m)/(fact(temp)*fact(m-temp));
               p1 += ways*(pow(l1, temp)*pow((l2-l1), (m-temp)));
               temp++;
           }
           temp = gcd(p1, p2);
           cout << p1/temp << "/" << p2/temp;
       }
       cout << '\n';
   }
   return 0;
}

Output:-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT