这个函数是c++ STL里自带的函数,应该需要引用头文件#include<iostream>

  功能:在一个有序的序列中查找可以将value(一个变量)放在队列里面而不会引起序列长度变化,单调性变化,或者顺序混乱的位置!!!记住是位置。而且它不会帮你替换,它只会告诉你它的位置,然后替换只能你自己来。

  原理:这个算法运用二分查找的方法找到合适的位置并返回。

  使用范围:可以在求最长上升子序列中使用,可以将时间复杂度降到O(nlogn)。

使用代码:

#include<iostream>
using namespace std;
int main(){
int a[],n,value;
cin>>n>>value;
for(int i=;i<=n;i++){
cin>>a[i];
}
*lower_bound(a+,a++n,value)=value; //因为是从下标1开始计算的,所以在数组名字前都加1
for(int i=;i<=n;i++){
cout<<a[i]<<" ";
}
}

输入:5 3     输出:1 2 3 5 6

1 2 4 5 6

谢谢大家观看,如果想详细了解它的应用,可以看一下我的其他文章:传送门

关于函数lower_bound()如何使用的问题的更多相关文章

  1. 二分检索函数lower_bound()和upper_bound()

    二分检索函数lower_bound()和upper_bound() 一.说明 头文件:<algorithm> 二分检索函数lower_bound()和upper_bound() lower ...

  2. 二分函数 lower_bound()

    这篇博客说是STL源码.... https://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html 头文件 algorithm 1.lowe ...

  3. STL函数 lower_bound 和 upper_bound 在算法竞赛中的用法

    以前比较排斥这两个函数,遇到需要二分的情景都是手写 \(while(left<=right)\). 这次决定洗心革面记录一下这两个函数的在算法竞赛中的用法,毕竟一般不会导致TLE. 其实百度百科 ...

  4. 两个很实用很方便的函数核心及用法{(lower_bound)+(max_element))~~

    (1)            关于 lower_bound(a,a+n,x)-a的用法:                                                求x在数组a中的 ...

  5. lower_bound和upper_bound函数

    lower_bound(ForwardIter first,ForwardIter last,const_TP & val) upper_bound(ForwardIter first,For ...

  6. C++ lower_bound 与 upper_bound 函数

    头文件: #include  <algorithm> 二分查找的函数有 3 个: 参考:C++ lower_bound 和upper_bound lower_bound(起始地址,结束地址 ...

  7. c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例

    c++ stl集合set介绍 c++ stl集合(Set)是一种包含已排序对象的关联容器.set/multiset会根据待定的排序准则,自动将元素排序.两者不同在于前者不允许元素重复,而后者允许. 1 ...

  8. STL之lower_bound和upper_bound

    ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, la ...

  9. STL lower_bound upper_bound binary-search

    STL中的二分查找——lower_bound .upper_bound .binary_search 二分查找很简单,原理就不说了.STL中关于二分查找的函数有三个lower_bound .upper ...

随机推荐

  1. 第一天学习如何使用markdown写日志,一起来看看成果吧!

    目录 一级标题 二级标题 一级标题 二级标题 ==黄色== one two three one two three 性别 年龄 男 150 H~2~o hello markdown hello mar ...

  2. Android APP 登陆模块

    首先我想强调一点.这个登陆的模块最好是放在另外一个线程里面来实现.否则有可能会爆出一系列的问题, 然后再与主UI 交互.这样就不会爆ANR异常 1.对于登陆模块的.首先大体的逻辑肯定是要清晰的.    ...

  3. java中位运算^,&,<<,>>,<<<,>>>总结

    1.^(亦或运算) ,针对二进制,相同的为0,不同的为1 public static void main(String[] args) { System.out.println("2^3运算 ...

  4. JS :Date日期格式化

    Date.prototype.format = function (formatStr) { var date = this; /* 函数:填充0字符 参数:value-需要填充的字符串, lengt ...

  5. ed-tue-robotics

    https://github.com/tue-robotics/ed ubuntu16.04 安装libsdformat4-dev ,libsdformat4 1./usr/include/sdfor ...

  6. overload和override的含义和区别

    重载(overload)和重写/覆盖(override)是Java多态性的不同表现形式. 重载(overload) (1) 重载是通过不同的方法参数来区分的,如不同的参数个数.顺序.类型. (2) 不 ...

  7. (ACM模板)队列queue

    #include<iostream> #include<cstdio> #include<queue> using namespace std; struct po ...

  8. Vue-native绑定原生事件

    首先介绍一下是什么意思: 意思就是当你给一个vue组件绑定事件时候,要加上native!如果是普通的html元素!就不需要 <div id = "app"> <m ...

  9. Flutter-底部導航欄切換

    程序入口 import 'package:flutter/material.dart'; import 'botton_navigation_widget.dart'; void main() =&g ...

  10. wraps的补充

    # import time# def index(name):# '''index函数'''# time.sleep(1)# print('Welcome %s to China'%name)# re ...