STL lower_bound upper_bound 用法
2024-10-07 19:11:49
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 ;
}
最新文章
- spring自动扫描、DispatcherServlet初始化流程、spring控制器Controller 过程剖析
- CoreData 数据模型的版本控制
- [ASE]sprint2 总结 &; sprint3计划
- angularjs 指令—— 绑定策略(@、=、&;)
- .Net事件管道详解图
- Web Service中的几个重要术语
- 熊猫TV提示“您的账号存在被盗风险,请在网站上登录解锁”
- [android警告] AndroidManifest.xml警告 Should explicitly set android:allowBackup to true or false
- 实现 kindle 原生系统、多看系弹出注释的通用写法
- 手动将MySQL服务安装到windows中
- HW2.5
- java打jar包 命令行cmd在当前路径打jar包
- 引用 IP电话的原理结构及其关键技术
- android 巧用资源文件(不断积累)
- linux虚拟机网络配制方法及遇到问题的解决方法
- iptables配置详解
- python之 正则表达式
- AsyncTask(异步任务)讲解-android的学习之旅(四十六)
- LeetCode(34)-Palindrome Number
- linux 下的OpenGL的安装配置
热门文章
- 饿了么 <;el-input>;<;/el-input>;输入框获取与失去焦点事件
- JMeter 阶梯式加压测试插件 Concurrency Thread Group
- Linux系统之-常用命令及技巧
- centos svn 安装
- 使用js在页面上新建文件夹
- Notepad++ 连接 FTP 实现编辑 Linux文件
- 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)
- python学习笔记:python操作redis
- 力扣算法——135Candy【H】
- 获取项目根目录(非tomact)