lower_bound: 在序列中找到第一个大于等于x 的数

upper_bound: 在序列中找到第一个大于x的数

条件:序列有序,且为升序

写法:

lower_bound(a + 1, a + 1 + n, x), upp....雷同

如何查找降序中第一个小于 \(x\) 的数呢?

bool cmp(const int& a, const int& b){return a > b;}
lower_bound(a + 1, a + 1 + n, x, cmp);

作用方便二分查找,进行简单替换

即得易见平凡,仿照上例显然,留作习题答案略,读者自证不难

反之亦然同理,推论自然成立,略去过程QED,由上可知证毕(多么美妙的证明)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-01-05
  • 2021-12-14
猜你喜欢
  • 2021-10-18
  • 2022-12-23
  • 2021-12-09
  • 2021-09-23
  • 2021-07-07
  • 2021-06-22
  • 2022-12-23
相关资源
相似解决方案