Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Your answer will be considered as correct if it has an absolute or relative error less than 10^(−6)

Tags:

c++

c

algorithm

In many Programming Problems, the above mentioned constraint is mentioned. I have seem this in codechef as well as SPOJ.

E.g. Link-1 , Link-2 and many more. (See the section OUTPUT in these two sample links)

What is the meaning of this constraint ? And how can I ensure that this constraint is specified by my output ?

like image 754
user1599964 Avatar asked Sep 18 '25 14:09

user1599964


1 Answers

Absolute error is:

|computedAnswer - correctAnswer|

Relative error is:

|(computedAnswer - correctAnswer) / correctAnswer|

Intuitively, absolute error is how far off the computed answer (or approximation) is from the correct (and possibly unknown) answer. Relative error is the ratio of the absolute error to the correct answer.

Thus, whether you are measuring the distance to the moon using a laser ranger or trying to place your left foot correctly during a fox-trot, your absolute error might be half a meter in either case. For the moon distance measurement, that would be pretty good; for the fox-trot, it would get you kicked off Dancing with the Stars.

like image 67
Ted Hopp Avatar answered Sep 21 '25 04:09

Ted Hopp