1384 全排列 next_permutation()函数
2017-10-08 19:29
197 查看
思路:
(1)将输入的字符数组转化为整数数组;
(2)使用qsort()函数将整数数组进行从小到大的快排;
(3)使用next_permutation()函数依次求出下一个排序。
next_permutation()函数需要引入头文件algorithm。
next_permutation有两个参数,第一个参数为数组的地址,第二个参数为该数组排序的最后一个位置的地址。
eg:
如果存在a之后的排列,就返回true,否则返回false。
所以输出可以写成:
(1)将输入的字符数组转化为整数数组;
(2)使用qsort()函数将整数数组进行从小到大的快排;
(3)使用next_permutation()函数依次求出下一个排序。
next_permutation()函数需要引入头文件algorithm。
next_permutation有两个参数,第一个参数为数组的地址,第二个参数为该数组排序的最后一个位置的地址。
eg:
int arr[3]; for(int i = 0; i < 3; i++){ arr[i] = 3 - i; } next_permutation(arr, arr + 3);
如果存在a之后的排列,就返回true,否则返回false。
所以输出可以写成:
do { for(int i = 0; i < strlen(arr); i++){ cout << arr[i]; } cout << endl; }while(next_permutation(arr, arr + strlen(arr)));
相关文章推荐
- 方格填数-用next_permutation()全排列函数做的
- 关于全排列 next_permutation() 函数的用法
- 关于全排列 next_permutation() 函数的用法
- 关于全排列 next_permutation() 函数的用法
- 【51nod】1384 全排列 next_permutation
- STL之全排列next_permutation()函数的用法
- next_permutation()函数 (数字1~10内实现全排列)
- STL快速全排列函数next_permutation与pre_permutation
- 51nod 1384 全排列 (dfs/next_permutation)
- 全排列(next_permutation)
- NYOJ 366 D的小L(从小到大输出排列。STL,next_permutation()函数的学习)
- 全排列 next_permutation()函数
- 2018_蓝桥_next_permutation()函数_全排列函数总结
- POJ 2718 Smallest Difference(暴力,全排列,next_permutation)
- next_permutation和prev_permutation(全排列)
- hdu 1027 输出第m个全排列(next_permutation)
- 计算下一个全排列(以STL中的next_permutation为例)
- 第一次写博客,记录一下刚才看到新的函数next_permutation()
- stl全排列next_permutation()与prev_permutation()函数用法
- C++STL中全排列函数next_permutation的使用