题意是求 n 个数在全排列中的第 m 个序列。
直接用 stl 中的 next_permutation(a, a+n) (这个函数是求一段序列的下一个序列的)
代码如下:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int a[
1005];
4 int main()
5 {
6 int n,m;
7 while(~scanf(
"%d%d",&n,&
m))
8 {
9 for(
int i =
0; i < n; ++
i)
10 a[i] = i+
1;
11 while(--m) next_permutation(a,a+
n);
12 printf(
"%d",a[
0]);
13 for(
int i =
1; i < n; ++
i)
14 printf(
" %d",a[i]);
15 puts(
"");
16 }
17 return 0;
18 }
View Code
转载于:https://www.cnblogs.com/Taskr212/p/9562458.html