//第一个,区间被划分成[1, mid], [mid + 1, r]
int bsearch_1(int l, int r)
{
while (l < r)
{
int mid = l + r >> 1;
if (check(mid)) r = mid; //判断mid是否满足性质
else l = mid + 1;
}
return l;
}
//第二个,区间被划分成[1, mid - 1], [mid , r]
int bsearch_2(int l, int r)
{
while (l < r)
{
int mid = l + r + 1 >> 1;
if (check(mid)) l = mid;
else r = mid - 1;
}
return l;
}
原文:https://www.cnblogs.com/jw-zhao/p/14769952.html