链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1027
Ignatius and the Princess II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5822 Accepted Submission(s): 3433
"Now I will show you the first problem." feng5166 says, "Given a sequence of number 1 to N, we define that 1,2,3...N-1,N is the smallest sequence among all the sequence which can be composed with number 1 to N(each number can be and should be use only once in this problem). So it's easy to see the second smallest sequence is 1,2,3...N,N-1. Now I will give you two numbers, N and M. You should tell me the Mth smallest sequence which is composed with number 1 to N. It's easy, isn't is? Hahahahaha......"
Can you help Ignatius to solve this problem?
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue> using namespace std; #define N 1100 int main()
{
int n, m; while(scanf("%d%d", &n, &m)!=EOF)
{
int a[N]; for(int i=; i<=n; i++)
a[i] = i; m--; while(m--)
{
next_permutation(a+, a+n+); /// next_permutation(数组名+起始位置,数组名+长度)
} for(int i=; i<=n; i++)
printf("%d%c", a[i], i==n?'\n':' '); }
return ;
}