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

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

Recently, I tried to solve problem 121C, but some weird things happened

Here is my 2 submissions

7567786 7567793

The first one gets AC, the second one gets TLE. The only difference between these 2 is in the second, i add " // " at line 77, at where the code line " cout<<" " ". Thus, if I cout<<" " at each loop, the result is OK, but if not, something happens and I get TLE. Please explain me! Thank you very much!

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

»
10 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

Please explain me!

undefined behaviors all over the place. I wonder how one of this submissions got AC, it's kind of miracle

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

On line 95 you use the variable j without initializing it.

Also you should be careful with log10(), it can return imprecise floating point values, and you may not get what you expect when converting the value to int.

  • »
    »
    10 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thanks for your response!

    I forgot what happened when I used pow without epsilon last time...

    But still, does cout command affect the initial value of variable? or something like this?

    • »
      »
      »
      10 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      When you invoke undefined behavior, you can expect any weird thing to happen.

      On the machine code level, this is probably because calling operator << accidentally leaves a zero in the register or memory area where j is supposed to be, and the program appears to work.