Yesterday when I was attending the CodeForces#100, I met a werid problem.
It was Problem A, I wrote my code, submitted, and passed the pretest, as usual. After the system test, I found that my code failed at test 9, it is:
Input: 2 1000 500
Output: NO
Answer: YES
status no. : 1011828
However, when I tested the data on my PC, I noticed that I' ve passed the test. My classmates told me that it might be the reason of O2 optimization of g++, because I don' t add that option on my PC, while CodeForces do. And Later on I submitted again with the MS Visual C++, this time my code was accepted(see status no. : 1010135), interesting, huh?
And something more interesting, if I add some "cout" before a statement(for debugging), I' ll pass the test in custom test:
See the status no. : 1011863
In this situation, I just add an cout << "" before I make my desicion.
And if I remove the cout << "":
I think this kind of results might have something with the O2 optimization, as the optimization may reduce the orders when it is compiling the source code.
EDIT: It appears that the problem probably actually has something to do with floating point precision: did you try adding an eps of 1e-8 when you compare doubles?
Unfortunately, IMO there's nothing to report :)
One should never compare precise double values, because there's no guarantee that compiler produced exactly the code we wrote.
Another instructive example is the following. You wrote DP (which computed, for example, maximum of some double function) and want to restore, at which value did the maximum achieved.
That's totally wrong! Due to some complex optimizations and, as a result, changing of double values, assignment "sel = i" could occur never.
That's not a bug because compilers are given freedom with operating with floating-point expressions, and it usually a very bad idea to compare doubles without epsilon.