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' ...
随机推荐
- linux修改文件系统注册设备
- tcpdump和windump
Tcpdump简介 tcpdump命令是一款sniffer工具,它可以打印所有经过网络接口的数据包的头信息, tcpdump,就是:dump the traffic on a network,根据使用 ...
- Windows安全应急响应(一)
入侵排查思路 检查账号安全 1.查看服务器是否有弱口令,远程管理端口是否对公网开放 2.查看服务器是否存在可以账号.新增账号 3.查看服务器是否存在隐藏账号.克隆账号检查方法:i.打开注册表,查看管理 ...
- We're sorry but mobile doesn't work properly without JavaScript enabled. Please enable it to continue.
vue过程中遇见这个问题:We're sorry but mobile doesn't work properly without JavaScript enabled. Please enable ...
- bootstrap的css和js
css:<link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel=" ...
- 边学边体验django
django菜鸟入门连接:http://www.runoob.com/django/django-template.html 安装以及Demo里面都有. 我边学边在电脑上演示,然后发现一些和实际不一样 ...
- Navicat permium快捷键
Ctrl + F 搜索本页数据 Ctrl + Q 打开查询窗口 Ctrl + / 注释sql语句 Ctrl + Shift + / 解除注释 Ctrl + R 运行查询窗口的sql语句 Ctrl + ...
- bzoj 3545
bzoj 3555 离线版本 线段树合并 做法是将询问和边权都排序 给每个点建一棵线段树 然后边建mst边回答询问 每次合并两个连通块的时候 要将两个连通块的线段树合并起来 线段树合并部分code i ...
- [Luogu] 遥远的国度
https://www.luogu.org/problemnew/show/P3979 3种情况 x=root,很显然此时应当查询整棵树 lca(root,x)!=x ,此时直接查询x的子树即可,与换 ...
- 2018 Nowcoder Multi-University Training Contest 1
Practice Link J. Different Integers 题意: 给出\(n\)个数,每次询问\((l_i, r_i)\),表示\(a_1, \cdots, a_i, a_j, \cdo ...