C++ STL:next_permutation和prev_permutation
两个函数都在#include <algorithm>里
顾名思义,next_permutation用来求下一个排列,prev_permutation用来求上一个排列。
当前的排列不满足函数能够继续执行的条件的时候,返回false,否则返回true
比如数组中已经是1,2,3,4,5了,就不能用prev_permutation了
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int data[5]={1,2,3,4,5};
while(next_permutation(data,data+5))
{
for (int i=0;i<5;i++)
cout<<data[i]<<" ";
cout<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int data[5]={1,2,3,4,5};
do
{
for (int i=0;i<5;i++)
cout<<data[i]<<" ";
cout<<endl;
}while(next_permutation(data,data+5));
return 0;
}
C++ STL:next_permutation和prev_permutation的更多相关文章
- STL next_permutation和prev_permutation函数
利用next_permutation实现全排列升序输出,从尾到头找到第一个可以交换的位置, 直接求到第一个不按升序排列的序列. #include <iostream> #include & ...
- STL中关于全排列next_permutation以及prev_permutation的用法
这两个函数都包含在algorithm库中.STL提供了两个用来计算排列组合关系的算法,分别是next_permutation和prev_permutation. 一.函数原型 首先我们来看看这两个函数 ...
- 打印全排列和stl::next_permutation
打印全排列是个有点挑战的编程问题.STL提供了stl::next_permutation完美的攻克了这个问题. 可是,假设不看stl::next_permutation,尝试自己解决,怎么做? 非常自 ...
- 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 算法原理和自行实现
目标 STL中的next_permutation 函数和 prev_permutation 两个函数提供了对于一个特定排列P,求出其后一个排列P+1和前一个排列P-1的功能. 这里我们以next_pe ...
- STL next_permutation 算法原理和实现
转载自:https://www.cnblogs.com/luruiyuan/p/5914909.html 目标 STL中的next_permutation 函数和 prev_permutation 两 ...
- STL - next_permutation 全排列函数
学习: http://blog.sina.com.cn/s/blog_9f7ea4390101101u.html http://blog.csdn.net/ac_gibson/article/deta ...
- C++ STL, next_permutation用法。
next_permutation 将按字母表顺序生成给定序列的下一个较大的序列,直到整个序列为 #include"iostream" #include"algorithm ...
- C++全排列函数next_permutation()和prev_permutation()
头文件:#include<algorithm> * * * 1. next_permutation(): next_permutation()函数的返回类型是bool类型. 即:如果有一个 ...
随机推荐
- Java 添加、读取、删除Excel文档属性
在文档属性中,可以设置诸多关于文档的信息,如创建时间.作者.单位.类别.关键词.备注等摘要信息以及一些自定义的文档属性.下面将通过Java程序来演示如何设置,同时对文档内的已有信息,也可以实现读取和删 ...
- 高级安全Windows防火墙概述以及最佳实践
本文简单介绍Windows防火墙的概念,给出使用场景并列出了常见的防火墙操作. 简介 在Windows NT6.0之后微软推出了高级安全Windows防火墙(简称WFAS),高级安全Windows防火 ...
- apache主配置文件httpd.conf详解
[root@lamp conf]# vi httpd.conf.bak 1 # 2 # This is the main Apache HTTP server configuration file. ...
- chromedriver和firefox driver的安装过程
环境:ubuntu14.04, python2.7 selenium2.0 文章参考出处:http://blog.csdn.net/heybob/article/details/52922645 ch ...
- Leetcode:面试题 04.03. 特定深度节点链表
Leetcode:面试题 04.03. 特定深度节点链表 Leetcode:面试题 04.03. 特定深度节点链表 先贴一下自己写过一个模板,按层数遍历: https://www.cnblogs.co ...
- 献给即将35岁的初学者,焦虑 or 出路?
导言:“对抗职场“35 岁焦虑”,也许唯一的方法是比这个瞬息万变的商业社会跑得更快!” 一直以来,都有许多人说“程序员或测试员是个吃青春饭的职业”,甚至还有说“35 岁混不到管理就等于失业”的言论. ...
- 显示二维码-智能TFT模块
应用范例: 使用 TOPWAY Smart LCD (HMT050CC-C) 显示二维码 第一步 建立工程 ① 开 Editor 软件, 点击菜单栏建立新工程File --> New Proje ...
- CSS权威指南(第三版)
CSS权威指南(第三版).pdf 网盘: https://545c.com/file/24657411-425141851 获取码: 276922
- Hash存储模型、B-Tree存储模型、LSM存储模型介绍
每一种数据存储系统,对应有一种存储模型,或者叫存储引擎.我们今天要介绍的是三种比较流行的存储模型,分别是: Hash存储模型 B-Tree存储模型 LSM存储模型 不同存储模型的应用情况 1.Hash ...
- Django 表关系的创建
Django 表关系的创建 我们知道,表关系分为一对多,多对多,一对一 我们以一个图书管理系统为背景,设计了下述四张表,让我们来找一找它们之间的关系 Book与Publish表 找关系:一对多 左表( ...