Tanky WooRSS

HDU/HDOJ 1027 Ignatius and the Princess II(STL)

16 Apr 2011
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1027

直接运用STL的中的next_permutation即可!

注意只用M-1次,因为1,2...N已经是第一次了。

#include 
#include 
using namespace std;

int N, M;
int arr[1005];

int main()
{
    while(cin >> N >> M)
    {
        memset(arr, 0, sizeof(arr));
        for(int i=0; i<N; ++i)
            arr[i] = i+1;
        for(int i=1; i<M; ++i)
            next_permutation(arr, arr+N);
        bool flag = 0;
        for(int i=0; i<N; ++i)
        {
            if(flag)
                cout << " ";
            flag = 1;
            cout << arr[i];
        }
        cout << endl;
    }

}