头文件 #include<algorithm>

#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main()
{
///第一种
int a[]={,,,,};
int it1,it2;
it1=lower_bound(a,a+,)-a;
it2=upper_bound(a,a+,)-a;
printf("%d %d\n",it1,a[it1]);
// /*输出*/ 2 4
printf("%d %d\n",it2,a[it2]);
// /*输出*/ 4 6 ///第二种
vector<int>vec;
vec.push_back(),vec.push_back();
vec.push_back(),vec.push_back();
vec.push_back(); vector<int>::iterator it11,it22;
it11=lower_bound(vec.begin(),vec.end(),);
it22=upper_bound(vec.begin(),vec.end(),);
it1=lower_bound(vec.begin(),vec.end(),)-vec.begin();
it2=upper_bound(vec.begin(),vec.end(),)-vec.begin();
printf("%d %d\n",it1,*it11);
// /*输出*/ 2 4
printf("%d %d\n",it2,*it22);
// /*输出*/ 4 6   /// 若是数组内未出现的值 如3 则输出均为 2 4 return ;
}

结构体也可使用

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;
struct NODE
{
int x,y;
bool operator<(const NODE& p)const{
if(x==p.x) return y>p.y;
return x<p.x;
}
}a[];
int main()
{
int len=;
a[len].x=, a[len++].y=;
a[len].x=, a[len++].y=;
a[len].x=, a[len++].y=;
a[len].x=, a[len++].y=;
sort(a,a+len);
printf("sort:\n");
for(int i=;i<len;i++)
printf("%d %d\n",a[i].x,a[i].y);
printf("\n"); int ind=lower_bound(a,a+len,(NODE){,})-a;
printf("%d %d %d\n",ind,a[ind].x,a[ind].y); return ;
}

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

  1. C/C++-STL中lower_bound与upper_bound的用法以及cmp函数

    转载于:http://blog.csdn.net/tjpuacm/article/details/26389441 不加比较函数的情况: int a[]={0,1,2,2,3}; printf(&qu ...

  2. hdu 4268 贪心+set lower_bound用法

    http://acm.hdu.edu.cn/showproblem.php?pid=4268 A想用手里的牌尽量多地覆盖掉B手中的牌.. 牌有h和w 问A手中的牌最多能覆盖B多少张牌 iterator ...

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

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

  4. 关于lower_bound( )和upper_bound( )的常见用法

    lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的. 在从小到大的排序数组中, lower_bound( begin,end,num):从数 ...

  5. lower_bound( )和upper_bound( )的常见用法

    lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的. 在从小到大的排序数组中, lower_bound( begin,end,num):从数 ...

  6. STL 源码分析《5》---- lower_bound and upper_bound 详解

    在 STL 库中,关于二分搜索实现了4个函数. bool binary_search (ForwardIterator beg, ForwardIterator end, const T& v ...

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

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

  8. Java实现 lower_bound() 和 upper_bound()

    Java实现 lower_bound() 和 upper_bound() lower_bound() 函数 lower_bound() 在 [begin, end) 进行二分查找,返回 大于或等于 t ...

  9. lower_bound( )和upper_bound( )怎么用嘞↓↓↓

    lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的. 在从小到大的排序数组中, lower_bound( begin,end,num):从数 ...

随机推荐

  1. Qt 线程基础(QThread、QtConcurrent、QThreadPool等)

      使用线程 基本上有种使用线程的场合: 通过利用处理器的多个核使处理速度更快. 为保持GUI线程或其他高实时性线程的响应,将耗时的操作或阻塞的调用移到其他线程. 何时使用其他技术替代线程 开发人员使 ...

  2. RF中alert的处理

    那么在robotframework中如何处理呢? 我在测试过程中遇到了这么一个窗口: 这种应该是属于Confirm 类型,是无法定位到的,在robotframework中需要这样处理: 1.虽然无法定 ...

  3. HTML-参考手册: Px、Em 换算工具

    ylbtech-HTML-参考手册: Px.Em 换算工具 1.返回顶部 1. Px.Em 换算工具 以下工具提供了em和px的换算工具. 第一个输入框:设置了网页默认的字体像素 (通常 16px) ...

  4. 剑指offer第二版面试题4:替换空格(JAVA版)

    题目:请实现一个函数,把字符串中的每个空格替换成“%20”.例如输入“We are happy”,则输出”We%20are%20happy”. 原因:在网络编程中,如果URL参数中含有特殊字符,如:空 ...

  5. Git 学习第二天(一)

    继续昨天的学习. 回顾一下,昨天我们安装了git 并创建了登录名及邮箱,还向git仓库提交了一个readme.txt的文本文件 下面,我们来修改下这个文件,将内容改为 Git is a distrib ...

  6. idea plugin 进度条

    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Switching Env") { @Ove ...

  7. 一、微服务概述与SpringCloud

    一.微服务概述与SpringCloud 1.微服务与微服务架构 微服务强调的是服务的大小,它关注的是某一个点,是具体解决某一个问题/提供落地对应服务的一个服务应用,狭意的看,可以看作Eclipse里面 ...

  8. 2019-4-29-.NET-Standard

    title author date CreateTime categories .NET Standard lindexi 2019-4-29 12:7:26 +0800 2018-2-13 17:2 ...

  9. 笔记34 Spring MVC的高级技术——处理multipart形式的数据

    一.需求介绍: Spittr应用在两个地方需要文件上传.当新用户注册应用的时候,我 们希望他们能够上传一张图片,从而与他们的个人信息相关联.当用 户提交新的Spittle时,除了文本消息以外,他们可能 ...

  10. WindowsPowerShell常用命令

    zai 获得Shell权限之后,可使用如下命令对系统进行文件操作: cd 后跟相应参数: cd ../ 返回上一级目录 cd +路径 跳转至制定目录(如果路径存在且正确的话) type flag.tx ...