二分模版之一
#include <iostream>
using namespace std;
int main() {
int arr[5] = {1,2,3,5,6};
int l = 0,r = 5-1;
int target = 5;
while (l<r) {
int mid = l + r >> 1;//大于等于目标向下取整 小于等于目标向上取整
if (arr[mid] >= target) {
r = mid; // 等于和等于放一起
} else {
l = mid+1;
}
}
cout << l << endl;
}