0

Why is my solution not working..I calculated the common diff and checked for whi...

 2 years ago
source link: http://codeforces.com/blog/entry/98509
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

By dd_07, history, 85 minutes ago,

83 minutes ago, # |

77 minutes ago, # |

I also tried to solve this ques by dividing and finding the 'd', but I think that's the problem, decimal quantities always have a precision issue.

66 minutes ago, # |

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)

  • 19 minutes ago, # ^ |

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

64 minutes ago, # |

In order to check if 2 real numbers are equal, aa and bb for example, you should check if |a−b|≤ϵ|a−b|≤ϵ where ϵϵ is a small enough value, for instance 10−910−9.


In this case have to check if ab=cab=c, why don't you just check if c∗b=ac∗b=a ?

  • 22 minutes ago, # ^ |

    Rev. 2  

    0

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

63 minutes ago, # |

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.

  • 20 minutes ago, # ^ |

    Thanks a lot bro..Solved;)

36 minutes ago, # |

141166574
Solution without using double
Thanks LetterC67


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK