首页 > 其他 > 详细

洛谷 P1008 火星人

时间:2019-03-05 21:21:47      阅读:170      评论:0      收藏:0      [点我收藏+]

链接: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,生成字典序的上一个排列

洛谷 P1008 火星人

原文:https://www.cnblogs.com/harutomimori/p/10479712.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!