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

Автор sia, история, 5 лет назад, По-английски

Hi, I was trying to solve the problem Traffic Lights from codeforces round 29 I was able to solve the problem but can somebody explain how just changing the language from C++14 to C++17 causes a change in the verdict
Wrong Answer Solution
Accepted Solution

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

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

float/double are not precise, they usually don't give accurate results.

You can even try that yourself on CUSTOM INVOCATION on codeforces,

double x=(double)1/1001 now output x and x*1001, now x*1001=0.9999.... & not 1, happens because the value stored in x is not exactly 1/1001 (rather a value very close to that)

And now coming to your solution, it passed on C++17 by luck :)

You can try your code in CUSTOM INVOCATION on C++17, just output c after you have done c=c-floor(c), now on both C++14/C++17 your final answer will be 2 and not 1002