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

Автор death_bringer, история, 3 года назад, По-английски

Hi Codeforces, I was trying to solve yesterday's 1622C - Set or Decrease and made this submission which failed at test case 3 but after a bit of cleaning up In code I made this submission and this was accepted. Can anyone please help me and explain why this happened?

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

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

The main difference is your wrong submission is making k as float and your correct one is making (k-second) as float, so both is different.

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

    Yeah, that's the difference but why is it any different logically. Making K as a float is going to change k-second into float. So logically both of them have to be the same.

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

      For float division either of numerator or denominator has to be floating value.Well , it is not a fact by belief that (float)k — second is not making numerator float type.

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

      Basically float has terrible precision. It uses 32 bits iirc, so by using float before the — you're losing a ton of precision. Never use float unless you need to due to memory (float uses 32 bits and double uses 64 bits or something like this) or you know that you don't need good precision.