Files
python/TangDou/AcWing/low_bounde_test.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

23 lines
540 B
C++

#include <bits/stdc++.h>
using namespace std;
const int su = 5;
int up[su] = {10, 8, 6, 5, 3};
int main() {
//目标:找数组中比目标值小、最左侧的一个数字
int x = 4;
int k;
for (k = 0; k < su; k++) if (up[k] < x) break;
if (k == su) cout << "找不到!" << endl;
else cout << k << endl;
int l = 0, r = su - 1;
while (l < r) {
int mid = (l + r) >> 1;
if (up[mid] < x) r = mid;
else l = mid + 1;
}
cout << l << endl;
return 0;
}