题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1027
题目大意:有一个从1到n的序列,求这个序列全排序的第m个序列。
题目思路:直接用STL中的next_permutation()函数。
AC代码:
// HDOJ
// 1027.cpp
/*
ID: Firwaless
LANG: C++
TASK: Ignatius and the Princess II
*/
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int i, n, m, cnt;
int arr[1005];
while (~scanf("%d%d", &n, &m))
{
cnt = 1;
for (i = 0; i < n; i++)
{
arr[i] = i + 1;
}
/* 使用STL中的next_permutation()函数 */
while (cnt < m)
{
cnt++;
next_permutation(arr, arr + n);
}
for (i = 0; i < n; i++)
{
if (i)
{
printf(" ");
}
printf("%d", arr[i]);
}
printf("\n");
}
return 0;
}