death_bringer's blog

By death_bringer, history, 2 years ago, In English

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?

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
2 years ago, # |
  Vote: I like it +2 Vote: I do not like it

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.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it +2 Vote: I do not like it

      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.

    • »
      »
      »
      2 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      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.