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

Автор dd_07, история, 2 года назад, По-английски
  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

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

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

»
2 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
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.