题目传送门

格式难调,题面就不放了。


  分析:

  这道题目不得不又让人感叹,还是$STL$大法好!!!

  $C++$的$algorithm$库中自带有$next\_permutation()$和$prev\_permutation()$函数,可以自动生成一个排列的下一个或上一个排列,那么这道题不久轻松被切了嘛~

  $STL$真的是个好东西。

  Code:

 

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;

int n,m,a[10001];

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1; i<=n; ++i) {
        cin>>a[i];
    }
    while( m-- ) next_permutation(a+1,a+n+1);
    for(int i=1; i<n; ++i) cout<<a[i]<<" ";
    cout<<a[n];
    return 0;
}

 

相关文章:

  • 2021-07-11
  • 2022-01-04
  • 2022-12-23
  • 2021-09-16
  • 2021-07-14
  • 2021-09-03
  • 2022-01-23
猜你喜欢
  • 2021-07-30
  • 2021-08-25
  • 2021-08-14
  • 2021-09-30
  • 2021-06-22
相关资源
相似解决方案