upper_bound()与lower_bound()的使用

c++中的许多库函数可以使我们的代码量大大减少,也可使问题简单化。很早之前就接触了upper_bound()与lower_bound(),但没怎么去研究

网上很多资料,最后我找到了一个简单易懂的。


#include <iostream>
#include <algorithm>//必须包含的头文件
using namespace std;
int main(){
int point[10] = {1,3,7,7,9};
int tmp = upper_bound(point, point + 5, 7) - point;//按从小到大,7最多能插入数组point的哪个位置
printf("%d\n",tmp);
tmp = lower_bound(point, point + 5, 7) - point;////按从小到大,7最少能插入数组point的哪个位置
printf("%d\n",tmp);
return 0;
}
output:
4
2

upper_bound()与lower_bound()的使用的更多相关文章

  1. 【刷题记录】 && 【算法杂谈】折半枚举与upper_bound 和 lower_bound

    [什么是upper_bound 和 lower_bound] 简单来说lower_bound就是你给他一个非递减数列[first,last)和x,它给你返回非递减序列[first, last)中的第一 ...

  2. [C++] upper_bound和lower_bound

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

  3. upper_bound和lower_bound的用法

    首先介绍这两种函数是什么意思 upper_bound是找到大于t的最小地址,如果没有就指向末尾 lower_bound是找到大于等于t的最小地址 题目链接:https://vjudge.net/con ...

  4. 二分查找、upper_bound、lower_bound

    整理及总结二分查找的判断和边界细节 修改版 package com.leej.binarysearch; import java.util.Arrays; /** * @author jerry * ...

  5. upper_bound()和lower_bound()

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

  6. C++中二分法之upper_bound()、lower_bound、binary_search()函数

    前言 数组.容器vector都适用,在头文件"algorithm"中 下面的例子是针对容器的,注意返回的是距离元素3最近的指针it,输出的是*it结果为元素4,假如我想得到位置而非 ...

  7. lower_bound && upper_bound

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

  8. hdu 5178(二分-lower_bound,upper_bound)

    pairs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. lower_bound和upper_bound函数

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

随机推荐

  1. [转]wx.getUserInfo(OBJECT) 微信小程序 获取用户信息

    本文转自:http://mp.weixin.qq.com/debug/wxadoc/dev/api/open.html wx.getUserInfo(OBJECT) 获取用户信息,withCreden ...

  2. T24银行核心业务系统

    T24银行核心业务系统 http://www.pianshen.com/search http://www.pianshen.com/article/8248107255/

  3. .net core 2.2 部署CentOS7(2)给虚拟机安装CentOS7

    目录: .net core 2.2 部署CentOS7(1)安装虚拟机 .net core 2.2 部署CentOS7(2)给虚拟机安装CentOS7 .net core 2.2 部署CentOS7( ...

  4. Builder 设计模式的学习

    Buileder(生成器)—对象创建型模式 一 意图 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 二 适用性 在以下情况使用Build模式: 1 当创建复杂对象的算法应 ...

  5. future3.2 Tomcat启动时错误:Cannot rename original file to ...

    其日志中第一个警告如下: 警告: Unexpected exception resolving reference java.io.IOException: Cannot rename origina ...

  6. POJ3126(KB1-F BFS)

    Prime Path   Description The ministers of the cabinet were quite upset by the message from the Chief ...

  7. Code Signal_练习题_Minesweeper

    In the popular Minesweeper game you have a board with some mines and those cells that don't contain ...

  8. tr,td高度不生效

    功能:表格内容较长,但是页面高度有限,超出显示滚动条 阻碍:给tr或者td加高度都不生效,不显示滚动条 解决方案:td中加div,设置高度和内容溢出时的样式 <table border='1' ...

  9. 基于Vue实现图片在指定区域内移动

    当图片比要显示的区域大时,需要将多余的部分隐藏掉,我们可以通过绝对定位来实现,并通过动态修改图片的left值和top值从而实现图片的移动.具体实现效果如下图,如果我们移动的是div 实现思路相仿. 此 ...

  10. CF954F Runner's Problem

    离散化+矩阵快速幂 首先看数据范围可以确定该题的算法为矩阵快速幂 然后易得转移矩阵 \[\begin{bmatrix} 1 & 1 & 0 \\ 1 & 1 & 1 \ ...