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 ...
随机推荐
- 5WHY分析法:一个问题分析与解决的工具
5WHY分析法很多做项目的都知道,但是却很少有人能用到实处,或者是灵活运用,所以今天小编又来翻一遍这个“旧账”,让大家更了解5WHY分析法. 什么是5WHY分析法? 所谓5why分析法,又称“5问法” ...
- plink: 等位型计数(allele count)
对genotype的等位型进行计数,需要用到以下参数: --freq Allele frequencies--counts Modifies --freq to report actual allel ...
- spring中获取当前项目的真实路径
总结: 方法1: WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext ...
- JSON的简单使用_解析前台传来的JSON数据
package cn.rocker.json; import org.junit.Test; import net.sf.json.JSONArray; import net.sf.json.JSON ...
- 【JS】js将 /Date(1518943415760+0800)/ 转换为2018-2-18 16:43:35格式
function formatDate(dt) { var year = dt.getFullYear(); var month = dt.getMonth() + 1; var date = dt. ...
- 阿里云申请ssl证书配置tomcat访问https
首先去阿里云上面申请ssl证书,免费的,自己百度去. 申请完ok之后会让你下载一个压缩包,里面有四个文件. 在tomcat安装目录下创建cert文件夹,把这四个文件扔进去 在conf/server.x ...
- Java 微信公众号导出所有粉丝(openId)
由于公众号换了公司主体,需要做迁移,玩家的openId数据需要做处理. (我是按我要的json格式,将粉丝导成了1万条数据的一个json文件) 文件格式: { "info":[ { ...
- string类型用法大全
使用标准C++中string类,要包含头文件< string > string类的构造函数 //string(const char *s); 用字符串s初始化 string s1(&quo ...
- Asp.net+WebSocket+Emgucv实时人脸识别
上个月在网上看到一个用web实现简单AR效果的文章,然后自己一路折腾,最后折腾出来一个 Asp.net+WebSocket+Emgucv实时人脸识别的东西,网上也有不少相关资料,有用winform的也 ...
- json日期字符串格式化时间
var str = '/Date(1333245600000+0800)/'; function data_string(str) { var d = eval('new ' + str. ...