1.lower_bound(begin,end,x)

返回第一个>=x的位置,找不到return .end()

2.upper_bound (begin,end,x)

返回第一个>x的位置,找不到return .end()

减掉begin得到下标

vector版

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
vector<int>a;
int b[];
int main(){ a.push_back();
a.push_back();
a.push_back();
a.push_back();
int p=lower_bound(a.begin(),a.end(),)-a.begin();
int q=lower_bound(a.begin(),a.end(),)-a.begin();
printf("%d %d\n",p,q);// 0 2 p=upper_bound(a.begin(),a.end(),)-a.begin();
q=upper_bound(a.begin(),a.end(),)-a.begin();
int r=upper_bound(a.begin(),a.end(),)-a.begin();
printf("%d %d %d\n",p,q,r);// 2 3 4 return ;
}

数组版

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
vector<int>a;
int b[]={,,,};
int main(){
int p=lower_bound(b,b+,)-b;
int q=lower_bound(b,b+,)-b;
printf("%d %d\n",p,q);// 0 2 p=upper_bound(b,b+,)-b;
q=upper_bound(b,b+,)-b;
int r=upper_bound(b,b+,)-b;
printf("%d %d %d\n",p,q,r);// 2 3 4 return ;
}

set (直接返回值)

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
using namespace std;
multiset<int>s;
int main(){
s.insert();
s.insert();
s.insert();
s.insert();
set<int>::iterator p=s.lower_bound();
set<int>::iterator q=s.lower_bound();
printf("%d %d\n",*p,*q);// 1 2
return ;
}

STL lower_bound upper_bound 用法的更多相关文章

  1. C++ lower_bound/upper_bound用法解析

    1. 作用           lower_bound和upper_bound都是C++的STL库中的函数,作用差不多,lower_bound所返回的是第一个大于或等于目标元素的元素地址,而upper ...

  2. [STL]lower_bound&upper_bound

    源码 lower_bound template <class ForwardIterator, class T> ForwardIterator lower_bound (ForwardI ...

  3. STL lower_bound upper_bound binary-search

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

  4. stl lower_bound upper_bound binary_search equal_range

    自己按照stl实现了一个:   http://www.cplusplus.com/reference/algorithm/binary_search/ 这里有个注释,如何判断两个元素相同: Two e ...

  5. 鬼知道是啥系列之——STL(lower_bound(),upper_bound() )

    引子,不明觉厉:   百度,渐入佳境: 头铁,入门到放弃: lower_bound(): 头文件:  #include<algorithm>函数功能:  函数lower_bound()在f ...

  6. lower_bound && upper_bound

     用lower_bound进行二分查找 ●在从小到大排好序的基本类型数组上进行二分查找. 这是二分查找的一种版本,试图在已排序的[first,last)中寻找元素value.如果[first,last ...

  7. STL中的二分查找———lower_bound,upper_bound,binary_search

    关于STL中的排序和检索,排序一般用sort函数即可,今天来整理一下检索中常用的函数——lower_bound , upper_bound 和 binary_search . STL中关于二分查找的函 ...

  8. C++ STL lower_bound()和upper_bound()

    lower_bound()和upper_bound()用法 1.在数组上的用法 假设a是一个递增数组,n是数组长度,则 lower_bound(a, a+n, x):返回数组a[0]~a[n-1]中, ...

  9. STL中的unique()和lower_bound ,upper_bound

    unique(): 作用:unique()的作用是去掉容器中相邻元素的重复元素(数组可以是无序的,比如数组可以不是按从小到大或者从大到小的排列方式) 使用方法:unique(初始地址,末地址): 这里 ...

随机推荐

  1. VC++ 字符串操作学习总结

    vc++中各种字符串(转载) http://www.cnblogs.com/tomin/archive/2008/12/28/1364097.html CString ,BSTR ,LPCTSTR之间 ...

  2. bash: service: command not found 错误的解决方法

    service命令是要用ROOT用户来执行的,而出错的用户是用su root切换到ROOT用户下,这个命令没有也不会把环境带过去! 用如下命令就不会出错了:su - root 注意:su 后面是一个空 ...

  3. vue常见面试题

    什么是 mvvm? MVVM 是 Model-View-ViewModel 的缩写.mvvm 是一种设计思想.Model 层代表数据模型,也可以在 Model 中定义数据修改和操作的业务逻辑:View ...

  4. upc组队赛2 Hakase and Nano【思维博弈】

    Hakase and Nano 题目描述 Hakase and Nano are playing an ancient pebble game (pebble is a kind of rock). ...

  5. PHP上传文件超过文件最大限制导致无法上传成功

    最近在学习<HeadFirst PHP & MySQL>一书的第5章"使用存储在文件中的数据",做一个文件上传的应用时,出现了错误,就是文件无法成功上传.这个问 ...

  6. SpringBoot扫描不到类,注入失败A component required a bean of type 'XXService' that could...

    SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描! “Application类”是指SpringBoot项目入口类.这个类的位置很关键: 如果App ...

  7. js系列教程11-json、ajax(XMLHttpRequest)、comet、SSE、WebSocket全解

    js系列教程11-json.ajax(XMLHttpRequest).comet.SSE.WebSocket全解:https://blog.csdn.net/luanpeng825485697/art ...

  8. 高级UI晋升之自定义View实战(八)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章自定义流式布局来进行介绍: 一般常见的流式布局由两种,一种是横向的个数固定 ...

  9. CF1158C

    题意:有排列p, 令\(nxt_i\)为\(p_i\)右侧第一个大于\(p_i\)的数的位置,若不存在则\(nxt_i=n+1\) 现在整个p和nxt的一部分丢失了,请根据剩余的nxt,构造出一个符合 ...

  10. ARC103

    ARC103E Tr/ee 首先没有叶子显然不科学,\(s_n\)是1也不怎么科学,\(s_i != s_{n-i}\)同样不怎么科学 特判掉上述情况后先把root记为1,链接(root,i+1)如果 ...