Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор mathturbator, история, 9 лет назад, По-английски

I have tested it against small test cases and all boundary cases but am still not able to find what the error is. Can somebody please guide/help me. Here is the link to my submission. Thanks in advance :)

http://codeforces.me/contest/552/submission/11695423

  • Проголосовать: нравится
  • -6
  • Проголосовать: не нравится

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

i guess it's precision problem..avoid using floats may be..

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

    But am not using it to calculate anything, just using it to calculate slope, which will be same even if my numerator and denominator are different(as in they still have same gcd to give same slope). I even used double. Its still wrong answer for test case 4.

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

Never trust in doubles :v , i mean that when you are using float , double , long double you can't compare with == , < , > as usual integer comparation , this issue happens because you are using operation a real number(can have infinite decimal digits — decimal periodic) in a double and you will lose precision because the number is truncated in some decimals , it is convenient to compare doubles with

abs(x - y) <  = EPS where EPS = 1e - 8

its enough for almost of problems or you need to change of focus and use only integers.

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

In calculating slope, one way is to keep it in p/q form where p and q are coprimes.