0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 22:48:48 +00:00

[60pts] #1224. [常中20180905 T1] 今天你AK了吗?

https://sjzezoj.com/submission/47985
This commit is contained in:
Baoshuo Ren 2022-01-22 09:02:14 +08:00
parent 2d2d74d42e
commit 690961b47b
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

49
S2OJ/1224/1224.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <cmath>
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
const int N = 100005;
int n;
long long k, permutation[N];
bool vis[N];
inline long long fact(long long x) {
long long res = 1;
while (x) {
res *= x--;
}
return res;
}
void revContor(int n, long long k) {
k--;
for (int i = 1; i <= n; i++) {
long long cnt = k / fact(n - i);
for (int j = 1; j <= n; j++) {
if (!vis[j]) {
if (!cnt) {
permutation[i] = j;
vis[j] = true;
break;
}
cnt--;
}
}
k %= fact(n - i);
}
}
int main() {
cin >> n >> k;
revContor(n, k);
for (int i = 1; i <= n; i++) {
cout << permutation[i] << ' ';
}
cout << endl;
return 0;
}