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 ;
}