![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
STL
innerdolphin
萌新一枚
展开
-
c++在有序序列中快速查找
刷题的时候经常会遇到这样的情况:假如我们需要在一个降序序列b中查找第一个小于x的数,该怎么快速完成呢?如果正常遍历,时间复杂度是O(n).如果编写一个二分查找函数,又比较浪费编码时间。cpp中的lower_bound()函数和upper_bound()函数就能解决这个问题,时间复杂度为O(logn).代码如下:#include <bits/stdc++.h>using namespace std;int a[6] = {1, 3, 5, 9, 14, 23};int b[6]原创 2022-01-18 16:51:32 · 618 阅读 · 0 评论 -
STL 优先队列 priority_queue 笔记
优先队列容器和队列一样,只能从队尾插入元素,从队首删除元素。优先队列可以用容器vector 或双向队列(deque)来实现。原创 2022-01-03 10:54:12 · 246 阅读 · 0 评论