nitishp05's blog

By nitishp05, history, 6 weeks ago, In English

Hey,

I need help in someone checking my solution to 1720A - Burenka Plays with Fractions #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

 
 
 
 
  • Vote: I like it
  • -11
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

Computations on floating point numbers are not that exact.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it
  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).