poj 1833 排列

http://poj.org/problem?id=1833

还是next_permutation.

这次是Int类型的

需要注意的是next_permutation是先判断时候有后继,返回一个bool值,如果为true,就转化到后继。

而next_permutation函数本书不考虑其值,就具有转化成后继的作用。

而且默认最后一个排列的下一个排列是第一个排列。

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <map>

using namespace std;
const int N=3E3+5;
int n ,m,k;
int a[N],b[N];

int main()
{
    cin>>m;
    while (m--)
    {
        cin>>n>>k;
      //  k = k % n;

        for ( int i = 0;i < n ; i++ )
        {
            scanf("%d",&a[i]);
        }
        while (k--)
        {
            next_permutation(a,a+n);
        }
        for ( int i = 0 ; i < n ; i++ )
        {
            printf("%d ",a[i]);
        }
        printf("\n");


    }


    return 0;
}

 

posted @ 2015-07-03 03:21  111qqz  阅读(98)  评论(0编辑  收藏  举报