HDU 1027 Ignatius and the Princess II(stl,next_permutation)
来源:互联网 发布:苹果手机怎么信任软件 编辑:程序博客网 时间:2024/05/01 15:57
HDU 1027 Ignatius and the Princess II
题目:求N个数全排列,顺着数第M个
next_permutation(a,a+n),这是我第一次用这个神奇的函数。以前根本不知道还有这种,能够进行全排列的函数,
与之完全相反的函数还有prev_permutation
a[0]=1;a[1]=2;a[2]=3;
do{cout << a[0]<< ” ” << a[1]<<” “<< a[2]<< endl;}while (next_permutation(a,a+3));
输出:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
如果改成 while(next_permutation(a,a+2));
则输出:
1 2 3
2 1 3
只对前两个元素进行字典排序
这是一道非常简单的题目,代码如下
#include <iostream>#include <string.h>#include <algorithm>using namespace std;long long n,m,num;int a[1005];int main(){ ios::sync_with_stdio(false); while(cin>>n>>m) { num=1; memset(a,0,sizeof(a)); for(int i=0; i<n; i++) { a[i]=i+1; } do{//这里要用do while if(num==m) { for(int i=0; i<n-1; i++) { cout<<a[i]<<" "; } cout<<a[n-1]; cout<<endl; //break; } num++; if(num>m) break; }while(next_permutation(a,a+n)); } return 0;}
0 0
- HDU 1027 Ignatius and the Princess II(stl,next_permutation)
- HDU 1027 Ignatius and the Princess II【STL- next_permutation全拍列】
- next_permutation & prev_permutation & hdu 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II (next_permutation)
- HDU 1027--Ignatius and the Princess II【next_permutation】
- Ignatius and the Princess II( next_permutation() )
- 【STL相关】hdu 1027 Ignatius and the Princess II【STL】
- Ignatius and the Princess II (HDU 1027) ——next_permutation排列函数
- HDU——1027Ignatius and the Princess II(next_permutation函数)
- HDU.1027 Ignatius and the Princess II【全排列:关于next_permutation问题】(3.14)
- HDU 1027 Ignatius and the Princess II next_permutation函数(也可以用DFS......)
- HDU 1027 Ignatius and the Princess II(next_permutation()的应用)
- HDU 1027 Ignatius and the Princess II (STL全排列)
- hdu 1027 Ignatius and the Princess II (STL 全排列)
- 【HDU 1027】【STL】 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II(STL全排列)
- 【HDU 1027 Ignatius and the Princess II】+ 全排列 + STL
- 【STL】hdu 1027 Ignatius and the Princess II
- 炮台攻击
- typedef用法
- JS实现百度地图
- 编译器对switch,case 的优化
- tensorflow笔记1——自动下载和安装 MNIST 到 TensorFlow 的 python 源码
- HDU 1027 Ignatius and the Princess II(stl,next_permutation)
- C语言与C++的基本区别
- 欢迎使用CSDN-markdown编辑器
- 单子设计模式(Singleton Pattern)
- EF+SQLSERVER控制并发下抢红包减余额(改进)
- Easypack之Alpine容器系列:Jenkins
- 估算程序的运行效率
- hdu5249--权值线段树
- js开放——封闭模式