Update appNew update is available. Click here to update.

Mohan and Magic Boots

Contributed by
Jaypal Mudaliyar
Last Updated: 23 Feb, 2023
Medium
yellow-spark
0/80
Avg time to solve 40 mins
Success Rate 70 %
Share
0 upvotes

Problem Statement

Mohan is walking on a street, Assume he is walking on the X-Axis. He is currently at point ‘0’ and needed to reach a point ‘N’.

On the way, he found magic boots which have a special property, it makes him teleport either to point ‘X+2’ by a probability of ‘P/100’ or otherwise to point ‘X+3’ if he is currently on point ‘X’.

Now as he has some urgent work to do after reaching point ‘N’, he wants to calculate the probability of reaching point ‘N’, and if that probability is strictly greater than ‘X/100’ then it means he will reach the point ‘N’ earlier, otherwise walking without magic boots he will reach earlier.

Being his friend he asked you to help him to calculate the probability to reach point ‘N’ and help him decide if it's helpful to pick up the boots or not. If the probability is strictly greater than ‘X/100’ you say ‘1’ or else you say ‘0’. Can you help him?.

EXAMPLE :
Input: ‘N’ = 2, ‘P' = 30, ‘X’ = 29

Output: 1
In this case, 
The probability to reach point ‘2(=N)’ while wearing the magic boots is 
‘P/100’ = 30/100 = 0.30 i.e. 0.30 > (‘X/100’ = 29/100 = 0.29). Hence the output will be ‘1’.
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
1 <= ‘T’ <= 10
1 <= ‘N’ <= 10^5
1 <= ‘P’ <= 100
1 <= ‘X’ <= 100
It is guaranteed that sum of ‘N’ over all test cases is <= 10^5
Time Limit: 1 sec
Sample Input 1 :
2
3 17 12
4 16 10
Sample Output 1 :
1
0
Explanation Of Sample Input 1 :
For the first test case, the probability of reaching point ‘3(=N)’ by wearing magic boots is ‘(100-P)/100’ = 83/100 = 0.83, which is greater than ‘X/100’ = 12/100 = 0.12.

Hence, the output will be: 1

For the second test case, the probability of reaching point ‘4(=N)’ by wearing magic boots and first getting teleported to point ‘2’ with a probability ‘P/100’ and then again getting teleported to point ‘4’ with a probability ‘P/100’ i.e. overall probability is ‘(P/100)*(P/100)’ = (16/100)*(16/100) = 256/10000 = 0.0256, which is less than ‘X/100’ = 10/100 = 0.10.

Hence, the output will be: 0
Sample Input 2 :
2
5 20 31
10 40 36
Sample Output 2 :
1
0
Reset Code
Full screen
Auto
copy-code
Console