1,is_permutation 函数,判断其中一个序列是不是另外一个序列的全排列。

包括四个参数,前两个是第一个数组需要判断的起始位置和终止位置。后两个是第二个数组需要判断的起始位置和终止位置。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. # define ll long long
  4. # define inf 0x3f3f3f3f
  5. const int maxn = 2e5+;
  6. int main(){
  7. int a[]={,,,,,,,};
  8. int b[]={,,,,,,,};
  9. int c[]={,,,,,,,};
  10. int d[]={,,,,,,,};
  11. int tmp;
  12. tmp=is_permutation(a,a+,d,d+); //
  13. cout<<tmp<<endl;
  14. tmp=is_permutation(a,a+,d,d+); //
  15. cout<<tmp<<endl;
  16. tmp=is_permutation(a,a+,d,d+); //
  17. cout<<tmp<<endl;
  18. }

next_permutation 函数 和 prev_permutation函数的使用方法。

包括两个参数第一个是需要全排列的起始位置和终止位置。

next是求下一个大于原排列的新的排列。

prev是求下一个小于原排列的新的排列。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. # define ll long long
  4. # define inf 0x3f3f3f3f
  5. const int maxn = 2e5+;
  6. int main(){
  7. int a[]={,,};
  8. next_permutation(a,a+);
  9. for(int i=;i<;i++){
  10. cout<<a[i]<<" ";
  11. }// 1 3 2
  12. cout<<endl;
  13. prev_permutation(a,a+);
  14. for(int i=;i<;i++){
  15. cout<<a[i]<<" ";
  16. }// 1 2 3
  17. cout<<endl;
  18. }

equal_range函数。

这个函数综合的了两个函数,第一个返回的是小于等于val的(lower_bound),第二个返回的是大于val的(upper_bound).返回的是一个pair类型的。

返回的两个分别的下标对应的数。

数组:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. # define ll long long
  4. # define inf 0x3f3f3f3f
  5. const int maxn = 2e5+;
  6. int a[maxn];
  7. int main(){
  8. for(int i=;i<=;i++){
  9. a[i]=i;
  10. }
  11. a[]=;
  12. // 1 2 3 4 4 6 7 8 9 10
  13. auto q=equal_range(a+,a++,);
  14. cout<<a[q.first-a]<<endl;// 4
  15. cout<<a[q.second-a]<<endl; // 6
  16. return ;
  17. }

vector

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. # define ll long long
  4. # define inf 0x3f3f3f3f
  5. const int maxn = 2e5+;
  6. vector<int>q;
  7. int main(){
  8. q.push_back();
  9. q.push_back();
  10. q.push_back();
  11. q.push_back();
  12. q.push_back();
  13. // 1 2 3 4 4 6 7 8 9 10
  14. auto t=equal_range(q.begin(),q.end(),);
  15. for_each(q.begin(),t.first,[](auto i){cout<<i<<" ";});// 1 2
  16. cout<<*t.first<<endl;//3
  17. cout<<*t.second<<endl;//
  18. return ;
  19. }

binary_search函数

查找当前有序区间是否存在val,如果有输出1,否则输出0

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. # define ll long long
  4. # define inf 0x3f3f3f3f
  5. const int maxn = 2e5+;
  6. vector<int>q;
  7. int main(){
  8. q.push_back();
  9. q.push_back();
  10. q.push_back();
  11. q.push_back();
  12. q.push_back();
  13. // 1 2 3 4 4 6 7 8 9 10
  14. int tmp=binary_search(q.begin(),q.end(),);
  15. cout<<tmp<<endl;// 1
  16. tmp=binary_search(q.begin(),q.end(),);
  17. cout<<tmp<<endl;// 0
  18. return ;
  19. }

STL之permutation/ equal_range/ binary_range学习的更多相关文章

  1. 《STL源码剖析》学习之traits编程

    侯捷老师在<STL源码剖析>中说到:了解traits编程技术,就像获得“芝麻开门”的口诀一样,从此得以一窥STL源码的奥秘.如此一说,其重要性就不言而喻了.      之前已经介绍过迭代器 ...

  2. stl源码剖析 详细学习笔记 算法总览

    //****************************基本算法***************************** /* stl算法总览,不在stl标准规格的sgi专属算法,都以 *加以标 ...

  3. stl源码剖析 详细学习笔记 set map

    // //  set map.cpp //  笔记 // //  Created by fam on 15/3/23. // // //---------------------------15/03 ...

  4. STL Stack(栈)学习笔记 + 洛谷 P1449 后缀表达式

    稍微看了看刘汝佳的白皮书,“实用主义”的STL实在是香到我了,而且在实验室大佬的推荐下我开始了stl的学习. 每篇附带一个题目方便理解,那行,直接开始. 毕竟是实用主义,所以就按照给的题目的例子来理解 ...

  5. stl源码剖析 详细学习笔记 空间配置器

    //---------------------------15/04/05---------------------------- /* 空间配置器概述: 1:new操作包含两个阶段操作 1>调 ...

  6. stl源码剖析 详细学习笔记 算法(4)

    //---------------------------15/03/31---------------------------- //lower_bound(要求有序) template<cl ...

  7. stl源码剖析 详细学习笔记 算法(1)

    //---------------------------15/03/27---------------------------- //算法 { /* 质变算法:会改变操作对象之值 所有的stl算法都 ...

  8. stl源码剖析 详细学习笔记 hashset hashmap

    //---------------------------15/03/26---------------------------- //hash_set { /* hash_set概述: 1:这是一个 ...

  9. stl源码剖析 详细学习笔记 hashtable

    //---------------------------15/03/24---------------------------- //hashtable { /* 概述: sgi采用的是开链法完成h ...

随机推荐

  1. 5WHY分析法:一个问题分析与解决的工具

    5WHY分析法很多做项目的都知道,但是却很少有人能用到实处,或者是灵活运用,所以今天小编又来翻一遍这个“旧账”,让大家更了解5WHY分析法. 什么是5WHY分析法? 所谓5why分析法,又称“5问法” ...

  2. plink: 等位型计数(allele count)

    对genotype的等位型进行计数,需要用到以下参数: --freq Allele frequencies--counts Modifies --freq to report actual allel ...

  3. spring中获取当前项目的真实路径

    总结: 方法1: WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext ...

  4. JSON的简单使用_解析前台传来的JSON数据

    package cn.rocker.json; import org.junit.Test; import net.sf.json.JSONArray; import net.sf.json.JSON ...

  5. 【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. ...

  6. 阿里云申请ssl证书配置tomcat访问https

    首先去阿里云上面申请ssl证书,免费的,自己百度去. 申请完ok之后会让你下载一个压缩包,里面有四个文件. 在tomcat安装目录下创建cert文件夹,把这四个文件扔进去 在conf/server.x ...

  7. Java 微信公众号导出所有粉丝(openId)

    由于公众号换了公司主体,需要做迁移,玩家的openId数据需要做处理. (我是按我要的json格式,将粉丝导成了1万条数据的一个json文件) 文件格式: { "info":[ { ...

  8. string类型用法大全

    使用标准C++中string类,要包含头文件< string > string类的构造函数 //string(const char *s); 用字符串s初始化 string s1(&quo ...

  9. Asp.net+WebSocket+Emgucv实时人脸识别

    上个月在网上看到一个用web实现简单AR效果的文章,然后自己一路折腾,最后折腾出来一个 Asp.net+WebSocket+Emgucv实时人脸识别的东西,网上也有不少相关资料,有用winform的也 ...

  10. json日期字符串格式化时间

    var str = '/Date(1333245600000+0800)/';   function data_string(str) {     var d = eval('new ' + str. ...