Problem of the day
'EQUATIONS' = { {“a”, ”s”} , {“s”, “r”} }
'VALUES' = { 1.5, 2 }
queries = { {“a”, “r” } }
For the above example (a / s) = 1.5 and (s / r) = 2 therefore (a / r) = 1.5 * 2 = 3.
The first line contains a single integer ‘T’ denoting the number of test cases. The test cases are as follows.
The first line of each test case contains two integers, ‘N’ and ‘Q,’ separated by a single space denoting the number of the equations and the number of queries, respectively.
The second line of each test case contains ‘N’ strings denoting the numerator variable of the 'EQUATIONS'.
The third line of each test case contains ‘N’ strings denoting the denominator variable of the 'EQUATIONS'.
The fourth line of each test case contains ‘N’ real numbers denoting the 'VALUE' of each fraction.
The fifth line of each test case contains ‘Q’ strings denoting the numerator variable for each query.
The sixth line of each test case contains ‘Q’ strings denoting the denominator variable for each query.
For each test case, return the value of the fraction up to 5 decimal places or -1 if the value of the fraction cannot be determined. All values are separated by a single space.
Your output will be considered correct if the relative error does not exceed 10^(-6).
You don’t need to print anything, It has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= N <= 100
1 <= Q <= 100
1 <= |S| <= 10
0.0 < values[i] <= 100.0
Where '|S|' denotes the length of the variables, and 'VALUES[i]' denotes the value of the i’th equation.
Time limit: 1 sec
2
2 1
a s
s r
1.5 2
a
r
3 2
a abc ab
x xyz xy
0.5 1 3.4
abc pqr
xyz rew
3.00000
1.00000 -1.00000
In test case 1, (a / s) = 1.5 and (s / r) = 2 therefore (a / r) = 1.5 * 2 = 3.
In test case 2, for the first query, the value of (abc / xyz) is given as 1, and the value of (pqr / rew) cannot be determined.
2
4 2
a r w p
r w p e
1.2 2.6 1 0.5
e a
p p
2 1
a x
b y
0.5 0.4
a
y
2.00000 3.12000
-1.00000
In test case 1, for the first query we have p / e = 0.5 ,therefore e / p = 1 / 0.5 = 2, for the second query (a / r) * (r / w) * (w / p) = a / p which is equal to 1.2 * 2.6 * 1 = 3.12.
In test case 2, we can not determine the value of the a / y, by the given set of equations. Thus return -1.