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

Автор Xclusive_OR, история, 2 года назад, По-английски

Problem Link

in the good function bool good(double x){ double temp=( x*x + sqrt(x) ); if(temp-c>0) return 0; else if(temp-c<=0) return 1; } why are we doing,

if(temp-c>0) return 0; else if(temp-c<=0) return 1;

instead of return temp-c== 0;

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

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

Because binary search is monotonic.

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

If you want to check for every possible value of x then you can write return temp-c==0 in good funtion. but that method gives you tle.so for reducing time limit you need to apply here binary search and making good funtion according to bs.