全排列函数next_permutation
生活随笔
收集整理的這篇文章主要介紹了
全排列函数next_permutation
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1620: 全排列
Time Limit: 1 Sec Memory Limit: 128 MB [Submit][Status][Web Board]Description
給定n個數 a[0] , a[1] … a[n-1], 輸出其全排列。
Input
第一行輸入一個數n,(n<7)
接下來一行輸入n個數。
Output
按字典序從小到大輸出全排列
Sample Input
3 1 2 3 3 1 2 2Sample Output
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 1 2 2 2 1 2 2 2 1AC代碼:
#include <stdio.h>#include <algorithm>using namespace std;int main(){int n;while(~scanf("%d",&n)){int a[n];for(int i = 0; i < n; i++)scanf("%d",&a[i]);sort(a,a+n);do{int i = 0;printf("%d",a[i]);for(i = 1; i < n; i++)printf(" %d",a[i]);printf("\n");}while(next_permutation(a,a+n));}return 0;}總結:
next_permutation為C++庫中全排列函數
使用:
總結
以上是生活随笔為你收集整理的全排列函数next_permutation的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: upper_bound()与lower_
- 下一篇: 全排列2