dd_07's blog

By dd_07, history, 2 years ago, In English
  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by dd_07 (previous revision, new revision, compare).

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

Because you are comparing double values with each other.

The answer to this test is 8, when your code tells 9.

1
11
1 -1 -100 -50 -60 2 -7 -25 -36 -4 3

Consider writing code without doubles or try to compare them proparly(std::abs(a — b) < eps)

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

    Thnx a lot bro for this idea std::abs(a — b) < eps

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In order to check if 2 real numbers are equal, $$$a$$$ and $$$b$$$ for example, you should check if $$$|a - b| \leq \epsilon$$$ where $$$\epsilon$$$ is a small enough value, for instance $$$10^{-9}$$$.


In this case have to check if $$$\frac{a}{b} = c$$$, why don't you just check if $$$c * b = a$$$ ?

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

    Thanks a lot bro..tried both the approach.I wasnt aware of |a−b|≤ϵ

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it
d1 = j - i
n1 = a[j] - a[i]
d2 = i - k
n2 = a[i] - a[k]
if(d1 * n2 != d2 * n1)cnt++

this will remove division and get u ACed I hope, you can check my last submission.