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

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

Hello codeforces community , i am trying to solve this problem :link . I am getting WA in test 15 , but i copied the test case on my compiler codeblocks , it gives correct output which judge want (expected output) . In judge compiler they saying my code gives output 2 , but i checked in my compiler which gives output 1 , which is correct . Dont know why this happening .

My code : https://pastebin.com/NE3sRLrR

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

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

The problem with your code is that it is depending too much on the accuracy of log10() function and then typecasting it to the integer which is to the greatest integer function.

Suppose if a double nth(as in your code) = 3.999999999999 in my system and 4.00000000000 in your system, this will differ the whole answer. It is not a good option to depend too much on the accuracies of the system.

See this code, I just edited the 137th line in your code, type-casted from double to long double.

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

    Just asking, is it a good idea to use long double instead of double always to prevent precision loss? ( If there is no problem with memory limit ). I do not know if that will help.

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

      For similar reason we don't always use int64 instead of int32: Speed.

      Since long double uses more digits of precisions than double, it is slower than double (try multiplying two doubles and two long doubles and see the difference). I don't know any other disadvantage but I always use double and I've never got a WA due to precision if my algorithm is correct. For most of the time, using double is enough.