Codeforces и Polygon могут быть недоступны в период с 23 мая, 7:00 (МСК) по 23 мая, 11:00 (МСК) в связи с проведением технических работ. ×

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

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

For problem B, when i was accumulating the total time, i am getting WA, but when i am accumulating the total distance, and then calculating time from that it is getting accepted, can anyone reason out the problem ? Precision issues should be in both cases. :-o here is the link to the problem http://codeforces.com/problemset/problem/148/B

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

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

It is better, to provide link to your solution with accumulated time

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

    Hi,

    In http://codeforces.com/submissions/arpit_s

    1st solution from top 1144453 gives correct answer — here i am accumulating total distance and calculating time from that.

    4rth solution from top 1144243 gives Wrong answer — here i am accumulating total time and calculating distance from that. It gave WA where my answer differed from actual solution by 1. If precision issue is there, then it should be in both cases, isn't it ?

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

      No. You must use epsilon to compare doubles. x >= y -> (x > y || fabs(x - y) < 1e-9).

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

        hi, i actually i tried it during the contest, it is still giving WA.... why are you saying that precision issues will not come when we are accumulating total distance and calculating time from that ? Is there anyone who got it accepted by calculating distance from total time ?

        Thanks.

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

          My answer "No" was releated to the question "If precision issue is there, then it should be in both cases, isn’t it ?". The answer is NO, because calculations in double type can have some errors, but it is not necessarily. For example 2.0 — 1.0 == 1, but sqrt(15.0) * sqrt(15.0) != 15. Some formulas can produce errors, others not, some produce positive error, which helps you, other produce negative one, and you get WA. Use eps, and use it wisely.