Last active
March 15, 2021 00:18
-
-
Save akshatgoel/7c7d06c428a00e8d4ba827ca4bbac88c to your computer and use it in GitHub Desktop.
Binary search template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x = -1; | |
int z = n / 2; // any sane large enough value to split problem space | |
for (int b = z; b >= 1; b /= 2) { | |
while (f(x+b) < f(x+b+1)) x += b; | |
} | |
int k = x+1; | |
for (int b = z; b >= 1; b /= 2) { | |
while (!ok(x+b)) x += b; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment