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' ...
随机推荐
- jdk在window系统中的配置
其实配置很简单,百度上很多配置的复杂化了,今天办公室的某小白百度了半天也没有配置好. 我使用的是Linux ,就很多简单了很多编译器都是集成的,尤其是现在kali linux 系统觉得做得越来也好 ...
- mount命令解析
可以参考两位大神的理解 Linux mount 命令 Linux的mount命令详解
- 【2018-01-26】SqlServer 检查死锁和阻塞
利用sys.sysprocesses SQL进程检查是否出现死锁和阻塞 Sys.SysProcesses 系统表是一个很重要的系统视图,主要用来定位与解决Sql Server的阻塞和死锁 select ...
- Python+request 登录接口reponse的返回值token跨py文件的传递《二》
主要使用场景: 一般我们在进行接口测试时,依赖登录接口后reponse中的某些返回值,因此需要将login接口单独写一个py文件,另外的py文件均可调用login的reponse返回值使用.共用登录接 ...
- C# 可观察集合
static void Main() { var data = new ObservableCollection<string>(); data.CollectionChanged += ...
- HDU 3824/ BZOJ 3963 [WF2011]MachineWorks (斜率优化DP+CDQ分治维护凸包)
题面 BZOJ传送门(中文题面但是权限题) HDU传送门(英文题面) 分析 定义f[i]f[i]f[i]表示在iii时间(离散化之后)卖出手上的机器的最大收益.转移方程式比较好写f[i]=max{f[ ...
- mongod破解版的安装
navicat for mongodb 12,又叫做navicat 12 for mongodb,是针对mongodb软件而开发的一款管理软件,拥有高效图形用户界面,能够连接本地或远程的MongoDB ...
- 3、组件注册-@ComponentScan-自动扫描组件&指定扫描规则
3.组件注册-@ComponentScan-自动扫描组件&指定扫描规则 3.1 xml方式 benas.xml 导入context命名空间 <?xml version="1.0 ...
- sql server 存储过程的详解
SqlServer存储过程详解 1.创建存储过程的基本语法模板: if (exists (select * from sys.objects where name = 'pro_name')) dro ...
- js批量下载文件
关于兼容性问题: <a href="xxx.docx" target='_blank'></a> 下载文件时,这种写法是没有兼容性问题:但是下载图 ...