TLE_Automaton's blog

By TLE_Automaton, history, 10 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

»
10 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

»
10 months ago, # |
  Vote: I like it +5 Vote: I do not like it
»
10 months ago, # |
  Vote: I like it 0 Vote: I do not like it
Spoiler
»
10 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)

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

i made the same error yesterday while attempting div2 contest .

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Fr, biggest setback for me when A had wrong answer for me in yesterday's Div 2, I panicked too much after that (not a good habit but I can't help) and ended up submitting 2 more wrong submissions. Had I submitted correct A at once, I would have had a positive rating change instead of the negative one yesterday :(

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

if i divide like this ceil(k/double(n)), then??