首页 技术 正文
技术 2022年11月15日
0 收藏 366 点赞 4,781 浏览 1893 个字

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898