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;
# | User | Rating |
---|---|---|
1 | tourist | 3803 |
2 | Benq | 3783 |
3 | Radewoosh | 3602 |
4 | maroonrk | 3575 |
5 | fantasy | 3526 |
6 | ko_osaga | 3500 |
7 | ksun48 | 3491 |
8 | Um_nik | 3486 |
9 | jiangly | 3474 |
10 | orzdevinwang | 3461 |
# | User | Contrib. |
---|---|---|
1 | awoo | 180 |
2 | -is-this-fft- | 177 |
3 | nor | 169 |
4 | Um_nik | 168 |
5 | SecondThread | 164 |
6 | maroonrk | 163 |
7 | adamant | 161 |
8 | kostka | 160 |
9 | YouKn0wWho | 158 |
10 | errorgorn | 153 |
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;
Name |
---|
Because binary search is monotonic.
can u please elaborate a little more, I am having a hard time understanding why <= 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.