头文件 #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. RF中alert的处理

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

  2. Dubbo入门到精通学习笔记(十七):FastDFS集群的安装、FastDFS集群的配置

    文章目录 FastDFS集群的安装 FastDFS 介绍(参考:http://www.oschina.net/p/fastdfs) FastDFS 上传文件交互过程: FastDFS 下载文件交互过程 ...

  3. C#之winform 猜拳小游戏

    C#之winform 猜拳小游戏 1.建立项目文件 2.进行界面布局 2.1 玩家显示(控件:label) 2.2  显示玩家进行选择的控件(控件:label) 2.3 电脑显示(控件:label) ...

  4. 机器学习技法笔记:Homework #6 AdaBoost&Kernel Ridge Regression相关习题

    原文地址:http://www.jianshu.com/p/9bf9e2add795 AdaBoost 问题描述 程序实现 # coding:utf-8 import math import nump ...

  5. POJ 1873 UVA 811 The Fortified Forest (凸包 + 状态压缩枚举)

    题目链接:UVA 811 Description Once upon a time, in a faraway land, there lived a king. This king owned a ...

  6. 拾遗:编译安装 vim

    在非 Gentoo/Funtoo 系的 Linux 发行版上,软件仓库里的 vim 包可能没有加入 python 特性支持,会造成部分插件无法正常使用 一.下载 vim 源码包 ftp://ftp.v ...

  7. Java jar文件

    JAR(Java Archive)是基于ZIP文件格式的文件格式. 它用于捆绑Java应用程序或小程序的资源,类文件,声音文件,图像等. 它还提供数据压缩.一个JAR文件作为一种特殊类型的ZIP文件. ...

  8. awesome mac

    https://proxyman.app/ https://proxie.app/docs/#how-does-it-work https://github.com/kyleduo/TinyPNG4M ...

  9. vue中wath的源码实现

    前言 阅读本节,需要理解vue的数据驱动原理. 看这样一段代码 new Vue({ data: { msg: 'hello', say: 'hello world', }, watch: { msg( ...

  10. Aggregate report 聚合报告