fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int l = 0;
  7. int r = 1000;
  8. int x = 1000;
  9. // l and r denote our current bounds: we know that l <= x <= r
  10. while(l<r) {
  11. // we will ask about the number in the middle
  12. int m = (l+r)/2;
  13. // note: this is an integer division, thus e.g., for l=0, r=1 we get m=1/2=0
  14. if(x <= m)
  15. r = m;
  16. else
  17. l = m+1;
  18. }
  19. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Standard output is empty