C++ STL 排列 next_permutation prev_permutation
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> vec1;
for (int k=0;k<5;k++)
{
vec1.push_back(rand());
}
vector<int>::iterator vec_iter1;
for (vec_iter1 = vec1.begin();vec_iter1 != vec1.end();++vec_iter1)
{
cout << *vec_iter1 << " ";
}
cout << endl;
cout << "----------------------------------" << endl;
while (next_permutation(vec1.begin(),vec1.end()))
{
for (vector<int>::iterator vec_iter2 = vec1.begin(); vec_iter2 != vec1.end(); ++vec_iter2)
{
cout << *vec_iter2 << " ";
}
cout << endl;
cout << "----------------------------------" << endl;
}
system("pause");
return 0;
}
========================================
41 18467 6334 26500 19169
----------------------------------
41 18467 19169 6334 26500
----------------------------------
41 18467 19169 26500 6334
----------------------------------
41 18467 26500 6334 19169
----------------------------------
41 18467 26500 19169 6334
----------------------------------
41 19169 6334 18467 26500
----------------------------------
41 19169 6334 26500 18467
----------------------------------
41 19169 18467 6334 26500
----------------------------------
41 19169 18467 26500 6334
----------------------------------
41 19169 26500 6334 18467
----------------------------------
41 19169 26500 18467 6334
----------------------------------
41 26500 6334 18467 19169
----------------------------------
41 26500 6334 19169 18467
----------------------------------
41 26500 18467 6334 19169
----------------------------------
41 26500 18467 19169 6334
----------------------------------
41 26500 19169 6334 18467
----------------------------------
41 26500 19169 18467 6334
----------------------------------
6334 41 18467 19169 26500
----------------------------------
6334 41 18467 26500 19169
----------------------------------
6334 41 19169 18467 26500
----------------------------------
6334 41 19169 26500 18467
----------------------------------
6334 41 26500 18467 19169
----------------------------------
6334 41 26500 19169 18467
----------------------------------
6334 18467 41 19169 26500
----------------------------------
6334 18467 41 26500 19169
----------------------------------
6334 18467 19169 41 26500
----------------------------------
6334 18467 19169 26500 41
----------------------------------
6334 18467 26500 41 19169
----------------------------------
6334 18467 26500 19169 41
----------------------------------
6334 19169 41 18467 26500
----------------------------------
6334 19169 41 26500 18467
----------------------------------
6334 19169 18467 41 26500
----------------------------------
6334 19169 18467 26500 41
----------------------------------
6334 19169 26500 41 18467
----------------------------------
6334 19169 26500 18467 41
----------------------------------
6334 26500 41 18467 19169
----------------------------------
6334 26500 41 19169 18467
----------------------------------
6334 26500 18467 41 19169
----------------------------------
6334 26500 18467 19169 41
----------------------------------
6334 26500 19169 41 18467
----------------------------------
6334 26500 19169 18467 41
----------------------------------
18467 41 6334 19169 26500
----------------------------------
18467 41 6334 26500 19169
----------------------------------
18467 41 19169 6334 26500
----------------------------------
18467 41 19169 26500 6334
----------------------------------
18467 41 26500 6334 19169
----------------------------------
18467 41 26500 19169 6334
----------------------------------
18467 6334 41 19169 26500
----------------------------------
18467 6334 41 26500 19169
----------------------------------
18467 6334 19169 41 26500
----------------------------------
18467 6334 19169 26500 41
----------------------------------
18467 6334 26500 41 19169
----------------------------------
18467 6334 26500 19169 41
----------------------------------
18467 19169 41 6334 26500
----------------------------------
18467 19169 41 26500 6334
----------------------------------
18467 19169 6334 41 26500
----------------------------------
18467 19169 6334 26500 41
----------------------------------
18467 19169 26500 41 6334
----------------------------------
18467 19169 26500 6334 41
----------------------------------
18467 26500 41 6334 19169
----------------------------------
18467 26500 41 19169 6334
----------------------------------
18467 26500 6334 41 19169
----------------------------------
18467 26500 6334 19169 41
----------------------------------
18467 26500 19169 41 6334
----------------------------------
18467 26500 19169 6334 41
----------------------------------
19169 41 6334 18467 26500
----------------------------------
19169 41 6334 26500 18467
----------------------------------
19169 41 18467 6334 26500
----------------------------------
19169 41 18467 26500 6334
----------------------------------
19169 41 26500 6334 18467
----------------------------------
19169 41 26500 18467 6334
----------------------------------
19169 6334 41 18467 26500
----------------------------------
19169 6334 41 26500 18467
----------------------------------
19169 6334 18467 41 26500
----------------------------------
19169 6334 18467 26500 41
----------------------------------
19169 6334 26500 41 18467
----------------------------------
19169 6334 26500 18467 41
----------------------------------
19169 18467 41 6334 26500
----------------------------------
19169 18467 41 26500 6334
----------------------------------
19169 18467 6334 41 26500
----------------------------------
19169 18467 6334 26500 41
----------------------------------
19169 18467 26500 41 6334
----------------------------------
19169 18467 26500 6334 41
----------------------------------
19169 26500 41 6334 18467
----------------------------------
19169 26500 41 18467 6334
----------------------------------
19169 26500 6334 41 18467
----------------------------------
19169 26500 6334 18467 41
----------------------------------
19169 26500 18467 41 6334
----------------------------------
19169 26500 18467 6334 41
----------------------------------
26500 41 6334 18467 19169
----------------------------------
26500 41 6334 19169 18467
----------------------------------
26500 41 18467 6334 19169
----------------------------------
26500 41 18467 19169 6334
----------------------------------
26500 41 19169 6334 18467
----------------------------------
26500 41 19169 18467 6334
----------------------------------
26500 6334 41 18467 19169
----------------------------------
26500 6334 41 19169 18467
----------------------------------
26500 6334 18467 41 19169
----------------------------------
26500 6334 18467 19169 41
----------------------------------
26500 6334 19169 41 18467
----------------------------------
26500 6334 19169 18467 41
----------------------------------
26500 18467 41 6334 19169
----------------------------------
26500 18467 41 19169 6334
----------------------------------
26500 18467 6334 41 19169
----------------------------------
26500 18467 6334 19169 41
----------------------------------
26500 18467 19169 41 6334
----------------------------------
26500 18467 19169 6334 41
----------------------------------
26500 19169 41 6334 18467
----------------------------------
26500 19169 41 18467 6334
----------------------------------
26500 19169 6334 41 18467
----------------------------------
26500 19169 6334 18467 41
----------------------------------
26500 19169 18467 41 6334
----------------------------------
26500 19169 18467 6334 41
----------------------------------
请按任意键继续. . .
C++ STL 排列 next_permutation prev_permutation的更多相关文章
- C++ STL:next_permutation和prev_permutation
两个函数都在#include <algorithm>里 顾名思义,next_permutation用来求下一个排列,prev_permutation用来求上一个排列. 当前的排列不满足函数 ...
- P4163 [SCOI2007]排列——next_permutation
P4163 [SCOI2007]排列 注意要排序: next_permutation prev_permutation #include<cstdio> #include<cstri ...
- 使用STL的next_permutation函数
文章作者:姜南(Slyar) 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作. 下午研究了一下全排列算法,然后发现C++的STL有一个函数可以方便地生成全排列,这 ...
- suseoj 1208: 排列问题 (STL, next_permutation(A.begin(), A.end()))
1208: 排列问题 时间限制: 1 Sec 内存限制: 128 MB提交: 2 解决: 2[提交][状态][讨论版][命题人:liyuansong] 题目描述 全排列的生成就是对于给定的字符集或 ...
- C++ STL next_permutation() prev_permutation(a,a+n)用法。
int a[3] = {1,2,3}; a可能形成的集合为{1,2,3},{1,3,2},{2,1,3},{2,3,1},{3,1,2},{3,2,1}. {2,1,3}的prev是{1,3,2}, ...
- 【STL】next_permutation的原理和使用
1.碰到next_permutation(permutation:序列的意思) 今天在TC上碰到一道简单题(SRM531 - Division Two - Level One),是求给定数组不按升序排 ...
- stl算法:next_permutation剖析
在标准库算法中,next_permutation应用在数列操作上比较广泛.这个函数可以计算一组数据的全排列.但是怎么用,原理如何,我做了简单的剖析. 首先查看stl中相关信息.函数原型: templa ...
- 8-全排列next_permutation
C++中全排列函数next_permutation 用法 转载 2017年03月29日 14:38:25 1560 全排列参考了两位的博客 感谢! http://blog.sina.com.cn/s/ ...
- 九度OJ 1120 全排列 -- 实现C++STL中next_permutation()
题目地址:http://ac.jobdu.com/problem.php?pid=1120 题目描述: 给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列. 我们假设对于小写字母有'a' ...
随机推荐
- 关于Http协议与TCP协议的一些简单理解
TCP协议对应于传输层,而HTTP协议对应于应用层,从本质上来说,二者没有可比性.Http协议是建立在TCP协议基础之上的,当浏览器需要从服务器获取网页数据的时候,会发出一次Http请求.Http会通 ...
- 全文检索引擎在Django中的使用
Haystack 1.什么是Haystack Haystack是django的开源全文搜索框架(全文检索不同于特定字段的模糊查询,使用全文检索的效率更高 ),该框架支持Solr,Elasticsear ...
- 由java派生出来的证书错误
未安装请求对应接口证书时的异常:> javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: ...
- PaaS容器集群优化之路
1. 性能优化面对的挑战 以下是整个PaaS平台的架构 其中主要包括这些子系统: 微服务治理框架:为应用提供自动注册.发现.治理.隔离.调用分析等一系列分布式/微服务治理能力,屏蔽分布式系统的复杂度. ...
- java 接口方法超时异常处理 设置超时时间
原文:https://blog.csdn.net/coding_1994/article/details/87728374 使用线程池另起一个线程,可以使用 newFixedThreadPool() ...
- 连接mongodb服务器
连接mongodb有几种方法 一种是使用mongodb编译时生成的客户端进行连接,就是我们之前介绍过的mongo客户端 另一种是使用各种驱动进行连接 这次使用mongo客户端进行连接,之前我们启动了一 ...
- Pandas-Numpy-Scipy-Matplotlib
Ref:Using iloc, loc, & ix to select rows and columns in Pandas DataFrames 单纯的方括号只有两个用途:基于列的label ...
- css点击li里面的标签 点击当前标签字体加粗 之前的恢复原始状态
<div class="functionalNavigation"> <ul class="ulp"> <icon class=& ...
- evpp http server定制实现
evpp http server定制实现 evpp http server定制实现 evpp http server定制实现
- MVVM框架-MVVMLight
项目URL:http://www.mvvmlight.net/ 一.安装MVVMLight 在NuGet程序包中搜索MVVMLight,然后安装. 二.使用 安装完MVVMLight后项目中会自动生成 ...