洛谷 P1008 火星人

链接:https://www.luogu.org/problemnew/show/P1088

思路:直接上STL的next_permutation 

代码:

 1 #include<bits/stdc++.h>
 2 #define inf 0x3f3f3f3f
 3 typedef long long ll;
 4 const int M = int(1e5)*2 + 5;
 5 using namespace std;
 6 
 7 int a[M];
 8 
 9 int main()
10 {
11     int n; cin >> n;
12     int m; cin >> m;
13     for (int i = 0; i < n; i++) cin >> a[i];
14     for (int i = 0; i < m; i++)
15         next_permutation(a, a + n);
16     for (int i = 0; i < n; i++) cout << a[i] << " ";
17     cout << endl;
18     return 0;
19 }

备注:next_permutation生成字典序的下一个排列,与之相对的有pre_permutation,生成字典序的上一个排列

————————————————
心里有光,哪儿都美
原文地址:https://www.cnblogs.com/harutomimori/p/10479712.html