hriss95's blog

By hriss95, 6 years ago, In English,

Hello to everybody! I've been solving 305B - Continued Fractions and decided to just calculate the fractions. I know it's not the correct way, but I just wanted try in see what's going to happen, because as we all know — when there is precision, it's always interesting :D . So, I wrote a solution and indeed an interesting thing occurred. When I saw the test case on which my solution failed, I immediately copied it and tried it on my computer and it actually produced the correct answer. So I cheated on this test in order to see what's going to happen on the others. The exact same thing happened and that's why I'm writing this post. Does anybody have an idea why this happens. I think that it would be good for all of us who are not familiar with dealing with such situations if we discuss it here

Here is my submission: 4039640

PS: I tried to use some eps values in case of some small error but it still didn't work

  • Vote: I like it
  • -3
  • Vote: I do not like it

6 years ago, # |
Rev. 2   Vote: I like it +6 Vote: I do not like it

It's not good to write double1 == double2;

I'd replace ending with:

if (fabs(d - pq) < 1e-9)

And it works on test 4.

UPD: Ok, I cant find eps. It is very close to be equal and not equal for this values, some eps say NO on YES and vice-versa.

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

    Yes, I'm familiar with this, but now it gets WA#5 and if I make the error smaller it passes test 5 and gets WA#6. Without the error it passes both these tests. The interesting part is that on my machine I get the correct answers actually with double1 == double2. Just to say by the way... I can type the right solution for this one, but I think this discussion would be beneficial especially if we find the reason.

    • »
      6 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Basically it is depend on compiler and your machine, if they differ then double representation may be differ too.

      P.S. I mean differ from codeforces or another judge system.