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

Автор Abrar535, история, 6 лет назад, По-английски

On Educational Codeforces Round 43 Problem B this solution 37778558 in c++17 gives AC whereas this same solution 37798163 in c++14 gives WA, tried it with c++11 and c++ 5 also but giving WA only c++17 gives AC :/ Can anyone tell me why??

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

»
6 лет назад, # |
Rev. 5   Проголосовать: нравится +12 Проголосовать: не нравится

row = ceil((k-n)/double(m-1));

First rule of float numbers: never use float numbers.

row = (k-n + (m-2)) / (m-1);

This gives accepted. http://codeforces.com/contest/976/submission/37799166

P.S. not sure why it gives AC in C++17. Better optimizatior, maybe.

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

    Thank you , i got it now , that case is not picking up all the precisions and so ceiling was not working there , so integer ceiling or using a long double instead of double gives AC. Thanks a lot , lesson learned :)

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

      I actually wasn't exaggerating: never use double unless it's printf function and problem except a float answer. Almost all of the problem (on your and mine level at least) can be solved without float numbers, and you won't get a lot of problems using them. Just an advice, ofc.