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

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

In codeforces round 106 Div 2, for problem B I submitted a code which failed on pretest 1 but when I executed the same code for that pretest the output was correct and the output of my program as shown by the judge was different from the one that I was getting on my system. That is I was getting right output but the one shown by the judge for my program on that test case was wrong. Kindly, look into this matter and figure out what's wrong ? My code id 1167715.

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

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

You are using function pow() — calculation is doing in float numbers, so results may differ from machine to machine depending on compile flags.

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

    But even after typecasting it to (int) isn't working. Do I need to use something else other than pow() function for the same ?

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

      In fact, when you work with floats/doubles (in spite of compiler), you should remember that any number (including integers) can be stored like X+-EPS. So, pow(3, 3) can be 26.9999999999999. If you cast it to int, it becomes 26, not 27. It's better to use something like (int)(pow(3, 3) + 1e-9) here. There is a very good article on TopCoder about floating point arithmetics.

      You can try MSVC++ compiler instead of GCC. GCC's optimizer can give very strange results with floating point numbers, and they think that it's well-known not bug