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

Автор curious_mind, 11 лет назад, По-английски

For my submission to problem 499C - Crazy Town i was getting wrong answer on test case 1 but the output on my pc was correct.uncommenting the 14th line in the code(just a cout statement) shows correct expected output. Solution Code

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

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

as a rule of thumb "Never Test Doubles For Equality" ... due to the representation errors of course instead you should do that :

if(fabs(dist1+dist2 - dist) <= EPS){
// do something
}

where EPS is a very small value for allowed error .. maybe something like 1e-9

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I would also say think twice before you use double comparison.Do you really need it?

In most of them you won't, but if you do use as rawbear1826 described.

Implementation of what was said in the editorial. 9250239