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

Автор nitishp05, история, 19 месяцев назад, По-английски

Hey,

I need help in someone checking my solution to 1720A - Бурёнка играет с дробями #815 Div2, Problem A. 168812095 The number to multiply lower fraction is (higher_fraction/lower_fraction). Now to check if this number is integer or not, I used int(num) == num logic. If its equal num is int, else float. accordingly the number of claps.

Please let me know what i'm missing here.

Thanks

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

»
19 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Computations on floating point numbers are not that exact.

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

To compare a/b and c/d the best way is comparing a*d and c*b

»
19 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
  1. You need to use abs(a — b) < eps, not a == b to compare floats.
  2. Underflow can happen in this line: to_multiply = max(frac1, frac2)/minfrac

if frac1 = 1e9 (a = 1e9, b = 1) and frac2 = 1e-9 (c = 1, d = 1e9), then the result will be really close to zero (1e-18), so it might get rounded down to zero.

Pretty sure it's mainly case 2 as I got same problem during contest (168814722 fails, but 168833377 works).