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类型. 即:如果有一个 ...
随机推荐
- codewars--js--Pete, the baker
问题描述: Pete likes to bake some cakes. He has some recipes and ingredients. Unfortunately he is not go ...
- OpenResty 在马蜂窝广告监测中的应用
马蜂窝技术原创内容,更多干货请订阅公众号:mfwtech 广告是互联网变现的重要手段之一. 以马蜂窝旅游 App 为例,当用户打开我们的应用时,有可能会在首屏或是信息流.商品列表中看到推送的广告.如果 ...
- Cesium案例解析(五)——3DTilesPhotogrammetry摄影测量3DTiles数据
目录 1. 概述 2. 案例 3. 结果 1. 概述 3D Tiles是用于传输和渲染大规模3D地理空间数据的格式,例如摄影测量,3D建筑,BIM / CAD,实例化特征和点云等.与常规的模型文件格式 ...
- Android中通过Java代码实现ScrollView滚动视图-以歌词滚动为例
场景 实现效果如下 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改 ...
- Python模块之Requests
目录 Requests 模块 常规的get请求 基于ajax的get请求 常规的post请求 基于ajax的post请求 综合项目实战 requests模块高级 requests代理 验证码处理 Re ...
- 何时使用异步或同步AJAX
通常最好使用异步调用 通过优锐课核心java学习笔记中,我们可以看到,码了很多专业的相关知识, 分享给大家参考学习. AJAX代表异步JavaScript和XML,是一项允许异步更新网页的技术,这意味 ...
- 从零开始一个个人博客 by asp.net core and angular(三)
这是第三篇了,第一篇只是介绍,第二篇介绍了api项目的运行和启动,如果api项目没什么问题了,调试都正常了,那基本上就没什么事了,由于这一篇是讲前端项目的,所以需要运行angular项目了,由于前端项 ...
- 如何使用Acrok Video Converter Ultimate转换视频?
Acrok Video Converter Ultimate是一个功能强大的程序,可以帮助您转换几乎任何类型的视频格式,例如MKV,AVI,WMV,MP4,MOV,MTS,MXF,DVD,蓝光等. 下 ...
- ajax 携带参数传递 页面 查找
不从新定义只能传过来数字 ,不能穿字符串 完整的ajax 获取参数跳转页面
- MongoDB 添加用户名和密码
MongoDB 添加用户名和密码 我用的是 mongodb3.6,如果没有的话先安装. sudo apt install mongodb 终端输入mongo,首先添加管理用户, show dbs // ...