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类型. 即:如果有一个 ...
随机推荐
- 对c语言中static函数的理解
先看看前两篇博客:个人对头文件的理解.对声明和定义的理解. static 函数只在定义该static函数的cpp中可见,在其他cpp中是不可见的. 举个例子,我建立了一个project,该projec ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- php 页面分页样式 示例
<?php class SubPages { private $each_disNums; //每页显示的条目数 private $nums; //总条目数 private $current_p ...
- 地址ip丢失
好好的机器 ip地址没有了,好几台机器出现这个情况,目前判断是 NetworkManager 的问题: 先了解一下network和NetworkManager之间的区别,还有他们分别代表了什么. ...
- 交换机 路由器 防火墙asa 安全访问、配置 方式
这里交换机 路由器 暂时统称为 网络设备 我们一般管理网络设备采用的几种方法 一般来说,可以用5种方式来设置路由器: 1. Console口接终端或运行终端仿真软件的微机(第一次配置要使用此方式) ...
- 全文检索框架---Lucene
一.什么是全文检索 1.数据分类 我们生活中的数据总体分为两种:结构化数据和非结构化数据. 结构化数据:指具有固定格式或有限长度的数据,如数据库,元数据等. 非结构化数据:指不定长或无固定格式 ...
- 一个故事看懂Linux文件权限管理
前情回顾: 我通过open这个系统调用虫洞来到了内核空间,又在老爷爷的指点下来到了sys_open的地盘,即将开始打开文件的工作. 详情参见:内核地址空间大冒险:系统调用 open系统调用链 我是一个 ...
- Vue开发中的常用技巧(持续更新)
1. 监听子组件的生命周期例如有父组件Parent和子组件Child,如果父组件监听到子组件挂载mounted就做一些逻辑处理,常规写法可能如下: // Parent.vue <Child @m ...
- 将jsp页面转化为图片或pdf(一)(qq:1324981084)
java高级架构师全套vip教学视频,需要的加我qq1324981084 在项目中遇见了将jsp页面转化为pdf的问题,试过itext,但是itext需要标准的html代码,我的页面中的一些属性是it ...
- js—求数组中的最大最小值
参考链接:https://www.w3cplus.com/javascript/calculate-the-max-min-value-from-an-array.html Math.min.appl ...