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 ...
随机推荐
- unittest的使用二——生成基于html的测试报告
mac下的安装: 1.下载HTMLTestRunner.py文件,下载地址http://tungwaiyip.info/software/HTMLTestRunner.html,可以复制里面的内容到一 ...
- python爬虫获取图片
import re import os import urllib #根据给定的网址来获取网页详细信息,得到的html就是网页的源代码 def getHtml(url): page = urllib. ...
- spring mvc后端校验validator
springmvc中我们使用hibernate的校验框架validation: pom: <validator.version>5.2.4.Final</validator.vers ...
- Jqgrid pager 关于“local” dataType 动态加载数据分页的研究(没好用的研究结果)
系列索引 Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引 Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数.ColModel API.事件 ...
- flask flash消息
请求完成,让用户知道状态发生了变化,可以使用flash确认消息 示例: xx.py from flask import Flask,render_template,request,redirect,u ...
- JAVA核心技术I---JAVA基础知识(格式化相关类)
一:格式化相关类 (一)java.text包java.text.Format的子类 –NumberFormat:数字格式化,抽象类 DecimalFormat –MessageFormat:字符串格式 ...
- 11.享元模式(Flyweight Pattern)
面向对象的代价 面向对象很好地解决了系统抽象性的问题,同时在大多数情况下,也不会损及系统的性能.但是,在某些特殊的应用中下,由于对象的数量太大,采用面向对象会给系统带来难以承受的内存开销.比如: ...
- vue表单校验提交报错TypeError: Cannot read property 'validate' of undefined
TypeError: Cannot read property 'validate' of undefined at VueComponent.submitForm (plat_users.html: ...
- Ubuntu18.04 关闭和开启图形界面
关闭用户图形界面,使用tty登录. sudo systemctl set-default multi-user.target sudo reboot 开启用户图形界面. sudo systemctl ...
- ContentType组件
django提供的一个快速连表操作的组件 适用于:一个字段确定不了唯一: 如:pricepolicy表中,course_id和content_type中对应的课程类型id才能确定唯一: model.p ...