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

Автор mkagenius, 13 лет назад, По-английски

I think it has happened a while ago on codeforces itself, but I forgot the reason why this happens:
See this code and code below.
http://ideone.com/N7vzQ

and added 1 "cout"  to the code at 119 and result changes:
http://ideone.com/OXHpO

By adding cout <<" "; should not change 39 to 2. :|


My guess is , its compilers problem.
Thanks in Advance.

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

13 лет назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

i think it is because of using cout and printf  at the same time, not shure

UPD: ios::sync_with_stdio(true); is not helps
13 лет назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится
Invalid language was selected for this message
13 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Do you have -O2 enabled?
If yes, it's very common effect. Optimizer is guilty. This cout 'foribs' optimization of some code. It can change execution result, if you have arrays overflow or something like this.
Try to compile the first one without optimization and compare results.


  • 13 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    Thanks.
    Yes , you are right , Optimizer is guilty.

    In that case, if we are participating in online contest(where we cannot modify compiler-options) , shall we use "eps" as Alias told?

    But that means whenever I will compare doubles , I will have to use eps,
    that sounds like a headache. :(
    • 13 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится
      You always need to use eps. All floating point numbers are saved with some error. In computer 0.333333333333333333 can be equal to 1.0 / 3.0. It's not really good idea to hope that this error is less than type's precision and we don't need eps.