TLE_Automaton's blog

By TLE_Automaton, history, 4 months ago, In English

Please note that the return value of the ceil function is not an integer, but a float / double / long double.

When you use cout output, your ceil may return a value of 8.49371e+06 instead of 8493712.

If you want to use its return value for output, you need to convert it to an integer first.

Yesterday, I encountered this problem while working on problem B of Codeforces Round 926 (Div. 2), and I took a penalty and searched for the error for a long time (246502057 and 246508172).

It's really bad.

I hope what I said is helpful to you, XD.

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

»
4 months ago, # |
Rev. 2   Vote: I like it +55 Vote: I do not like it

you can do ceil without using the ceil function by doing this

lets say you want to ceil ( k / n ) so instead of writing ceil( k / n ) write this (k+n-1) / n

»
4 months ago, # |
  Vote: I like it +5 Vote: I do not like it
»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it
Spoiler
»
4 months ago, # |
  Vote: I like it +6 Vote: I do not like it

This has been said so many times, I'm really surprised you got to CM without knowing you shouldn't use floating point functions on integers...

Also another cool and simple to memorize way to do ceil is n/k + (n%k!=0)