NEED HELP!!unable to understand the problem in the code

I’ve tried hard but I’m not able to find the problem in my code for the problem ‘SEBI AND THE HIGHWAY’.I am getting wrong answer.

PROBLEM:-https://www.codechef.com/problems/SEBIHWY/
my code:-https://www.codechef.com/viewsolution/15035522

Firstly, the speed can be decimal, it need not be an integer. You should use double or float for it.

But after doing this, you will get error at if(b==c). Why?

The fact is, if you try to compare two float/double values, you may not get correct answer.

Eg, if i use the code-

double a=3.14,b=3.14;
if(a==b) print("YAY");
else print("Unequal");

It will print unequal, due to way how floating numbers are stored. 3.14 is not stored as 3.14, but as 3.14000001 . or perhaps 3.14000000000001. We dont know, but its clear that its all 0 till 6th decimal place. So instead of equality, we check if the two floating values are same till 6th decimal place.

I.e, instead of if(a==b) we use if(abs(a-b)<=0.000001)

This is one of the errors i noticed in your code. If WA persists, get back to m :slight_smile:

Hey,

The problem is with your conversion, since the speed is calculated relative so the actual speed of the other car will be S/3600 + D/(20T) when expressed in km/s. (D50)/(1000) km distance between them and T is in seconds and secondly either you have to use to float or double then only you’ll get correct answer.

Hope this helps! solution for better explanation