Блог пользователя Bobby_Fischer

Автор Bobby_Fischer, история, 20 месяцев назад, По-английски

Hello, Codeforces.

I've sent different submissions with same code with different compilers on problem Burenka Plays with Fractions from last round and got different results.

I would've gotten a higher rate if this strange thing hadn't happened.

Strange that I get wrong answer with modern compilers and accepted with old compilers !

Can anyone explain that ?!

  • Проголосовать: нравится
  • -11
  • Проголосовать: не нравится

»
20 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Likely, your code had an usage of what is known as Undefined behaviour. If this is the case, then we are unable to know, let alone guarantee, if your code works as expected in every compilation environment. You need to be cautious of these situations!

»
20 месяцев назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

It is never a good idea to directly compare floating-point numbers using the equality comparison operator.
As per why the results were different, the C++ standard isn't very stringent about what the extra digits should be after the minimum precision (about 16 digits for double), i.e., they are implementation-defined. The test-case on which your code gave the wrong answer (expected output : 2), your code's output was 0, because double may not have been precise enough to differentiate between 1000000000/999999999 and 999999999/999999998 in one compiler and was in the other.

»
20 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You shouldn't compare floating-point values using the == operator.

I resubmit your WA 13 C++17 (64) solution and get AC by turning on excess precision, but I wouldn't recommend relying on this method to get AC though.