Xclusive_OR's blog

By Xclusive_OR, history, 14 months ago, In English

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;

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

| Write comment?
»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Because binary search is monotonic.

  • »
    »
    14 months ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    can u please elaborate a little more, I am having a hard time understanding why <= 0

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

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.