头文件 #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. EM相关两个算法 k-mean算法和混合高斯模型

    转自http://www.cnblogs.com/jerrylead/archive/2011/04/06/2006924.html http://www.cnblogs.com/jerrylead/ ...

  2. python面试题之多线程好吗?列举一些让Python代码以并行方式运行的方法

    答案 Python并不支持真正意义上的多线程.Python中提供了多线程包,但是如果你想通过多线程提高代码的速度,使用多线程包并不是个好主意.Python中有一个被称为Global Interpret ...

  3. js 实用封装 点击按钮复制到剪贴板

    封装剪贴板: function Copy(str) { var save = function (e) { //设置需要复制模板的内容 e.clipboardData.setData('text/pl ...

  4. 【VUE/JS】vue和js禁止浏览器页面后退

    1.vue 禁止浏览器后退需求是:需要某个路由不能通过浏览器返回,同时不影响相互之间的切换整理一下解决方法 和 使用方法: 1.在路由配置中给这个路由添加meta信息,比如: { path: '/ho ...

  5. 关于js 重载

    拜读js忍者修炼一书 读到关于js函数重载内容这个模块 主要是介绍通过js的访问argument这个参数来实现js函数的重载 通过在函数内部进行判断js argument参数的长度 代码如下所示 va ...

  6. Android基础——框架模式MVC在安卓中的实践

    本篇文章包含以下内容: MVC的介绍 MVC的实践 MVC的介绍 MVC (Model View Controller),是模型(model)视图(view)控制器(controller)的缩写,一种 ...

  7. rest_framework 认证组件 权限组件

    认证组件 权限组件 一.准备内容 # models class User(models.Model): name = models.CharField(max_length=32) pwd = mod ...

  8. 2018-8-10-C#-配置文件存储-各种序列化算法性能比较

    title author date CreateTime categories C# 配置文件存储 各种序列化算法性能比较 lindexi 2018-08-10 19:16:52 +0800 2018 ...

  9. ADS 命令行命令介绍

    armasm 1. 命令:armasm [选项] -o 目标文件 源文件 2. 选项说明 -Errors 错误文件名        ;指定一个错误输出文件 -I 目录[,目录]          ;指 ...

  10. robotframework+python3+selenium之下拉框的选择---第五集

    由于我没有找到option形式的,所以借鉴其他大神的博客内容,如下: 1.F12后看见下拉框的源码是<option xxx> 2.如果F12后看到的下拉源码是这样的: <div xx ...