STL之permutation/ equal_range/ binary_range学习
1,is_permutation 函数,判断其中一个序列是不是另外一个序列的全排列。
包括四个参数,前两个是第一个数组需要判断的起始位置和终止位置。后两个是第二个数组需要判断的起始位置和终止位置。
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = 2e5+;
int main(){
int a[]={,,,,,,,};
int b[]={,,,,,,,};
int c[]={,,,,,,,};
int d[]={,,,,,,,};
int tmp;
tmp=is_permutation(a,a+,d,d+); //
cout<<tmp<<endl;
tmp=is_permutation(a,a+,d,d+); //
cout<<tmp<<endl;
tmp=is_permutation(a,a+,d,d+); //
cout<<tmp<<endl;
}
next_permutation 函数 和 prev_permutation函数的使用方法。
包括两个参数第一个是需要全排列的起始位置和终止位置。
next是求下一个大于原排列的新的排列。
prev是求下一个小于原排列的新的排列。
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = 2e5+;
int main(){
int a[]={,,};
next_permutation(a,a+);
for(int i=;i<;i++){
cout<<a[i]<<" ";
}// 1 3 2
cout<<endl;
prev_permutation(a,a+);
for(int i=;i<;i++){
cout<<a[i]<<" ";
}// 1 2 3
cout<<endl;
}
equal_range函数。
这个函数综合的了两个函数,第一个返回的是小于等于val的(lower_bound),第二个返回的是大于val的(upper_bound).返回的是一个pair类型的。
返回的两个分别的下标对应的数。
数组:
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = 2e5+;
int a[maxn];
int main(){
for(int i=;i<=;i++){
a[i]=i;
}
a[]=;
// 1 2 3 4 4 6 7 8 9 10
auto q=equal_range(a+,a++,);
cout<<a[q.first-a]<<endl;// 4
cout<<a[q.second-a]<<endl; // 6
return ;
}
vector
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = 2e5+;
vector<int>q;
int main(){
q.push_back();
q.push_back();
q.push_back();
q.push_back();
q.push_back();
// 1 2 3 4 4 6 7 8 9 10
auto t=equal_range(q.begin(),q.end(),);
for_each(q.begin(),t.first,[](auto i){cout<<i<<" ";});// 1 2
cout<<*t.first<<endl;//3
cout<<*t.second<<endl;//
return ;
}
binary_search函数
查找当前有序区间是否存在val,如果有输出1,否则输出0
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = 2e5+;
vector<int>q;
int main(){
q.push_back();
q.push_back();
q.push_back();
q.push_back();
q.push_back();
// 1 2 3 4 4 6 7 8 9 10
int tmp=binary_search(q.begin(),q.end(),);
cout<<tmp<<endl;// 1
tmp=binary_search(q.begin(),q.end(),);
cout<<tmp<<endl;// 0
return ;
}
STL之permutation/ equal_range/ binary_range学习的更多相关文章
- 《STL源码剖析》学习之traits编程
侯捷老师在<STL源码剖析>中说到:了解traits编程技术,就像获得“芝麻开门”的口诀一样,从此得以一窥STL源码的奥秘.如此一说,其重要性就不言而喻了. 之前已经介绍过迭代器 ...
- stl源码剖析 详细学习笔记 算法总览
//****************************基本算法***************************** /* stl算法总览,不在stl标准规格的sgi专属算法,都以 *加以标 ...
- stl源码剖析 详细学习笔记 set map
// // set map.cpp // 笔记 // // Created by fam on 15/3/23. // // //---------------------------15/03 ...
- STL Stack(栈)学习笔记 + 洛谷 P1449 后缀表达式
稍微看了看刘汝佳的白皮书,“实用主义”的STL实在是香到我了,而且在实验室大佬的推荐下我开始了stl的学习. 每篇附带一个题目方便理解,那行,直接开始. 毕竟是实用主义,所以就按照给的题目的例子来理解 ...
- stl源码剖析 详细学习笔记 空间配置器
//---------------------------15/04/05---------------------------- /* 空间配置器概述: 1:new操作包含两个阶段操作 1>调 ...
- stl源码剖析 详细学习笔记 算法(4)
//---------------------------15/03/31---------------------------- //lower_bound(要求有序) template<cl ...
- stl源码剖析 详细学习笔记 算法(1)
//---------------------------15/03/27---------------------------- //算法 { /* 质变算法:会改变操作对象之值 所有的stl算法都 ...
- stl源码剖析 详细学习笔记 hashset hashmap
//---------------------------15/03/26---------------------------- //hash_set { /* hash_set概述: 1:这是一个 ...
- stl源码剖析 详细学习笔记 hashtable
//---------------------------15/03/24---------------------------- //hashtable { /* 概述: sgi采用的是开链法完成h ...
随机推荐
- latex 导入pdf
pdflatex \includepdf[addtotoc={1,section,1,something would show in catalog,cc},pages=-,offset=0cm 0. ...
- 第二十二节,TensorFlow中RNN实现一些其它知识补充
一 初始化RNN 上一节中介绍了 通过cell类构建RNN的函数,其中有一个参数initial_state,即cell初始状态参数,TensorFlow中封装了对其初始化的方法. 1.初始化为0 对于 ...
- POJ 1743 Musical Theme (Hash)
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 33820 Accepted: 11259 D ...
- php mkdir No such file or director问题
有时使用mkdir创建目录时会出现 No such file or director这样的错误,导致这个错误的原是 比如你要创建目录 a\b\c目录,但是创建时父目录b也不存在时就会出现这样的问题. ...
- 浏览器报XMLHttpRequest cannot loadxxxxxx
解决方案 找到浏览器-----右击---属性---加 加上这一句就不会报错--allow-file-access-from-files 加上这一句就不会报错--allow-file-access-fr ...
- python字节(bytes)
在 3.x 中,字符串和二进制数据完全区分开.文本总是 Unicode,由 str 类型表示,二进制数据则由 bytes 类型表示.Python 3 不会以任意隐式的方式混用 str 和 bytes, ...
- Springboot -- 由于jar版本不匹配遇到的问题
网上整合dubbo的例子很多,我这边今天整合了一个例子,但是发现启动dubbo service时候,提示log4j日志类无法找到,启动client的时候,注入的service为空,调试了半天,编码并无 ...
- Storm中重要对象的生命周期
Spout方法调用顺势 declareOutputFields()(调用一次) open() (调用一次) activate() (调用一次) nextTuple() (循环调用 ) deactiva ...
- urllib 学习二
编码解码: python2 用法: urllib.urlencode() 编码 urlparse.parse_qs() 解码 python3 用法: urllib.parse.urlencode() ...
- MyBatis-获取 xxxMapper
Main 方法,mybatis 版本为 3.5.0 使用 MapperProxyFactory 创建一个 MapperProxy 的代理对象 代理对象里面包含了 DefaultSqlSession(E ...