arpit_s's blog

By arpit_s, 12 years ago, In English

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

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
12 years ago, # |
  Vote: I like it +3 Vote: I do not like it

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

  • »
    »
    12 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

      • »
        »
        »
        »
        12 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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 years ago, # ^ |
          Rev. 3   Vote: I like it +3 Vote: I do not like it

          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.