You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.3 KiB
C++
81 lines
2.3 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define CRP(t, x) const t &x
|
|
#define OPL(t, x) bool operator<(CRP(t, x)) const
|
|
#define FIL(x, v) memset(x, v, sizeof(x))
|
|
#define CLR(x) FIL(x, 0)
|
|
#define NE1(x) FIL(x, -1)
|
|
#define INF(x) FIL(x, 0x3f)
|
|
typedef long long ll, i64;
|
|
int a[1005];
|
|
struct MyStruct
|
|
{
|
|
int a[21], n;
|
|
OPL(MyStruct, rhs)
|
|
{
|
|
auto b = rhs.a;
|
|
for (int i = 1; i < n; i++)
|
|
{
|
|
if (a[i] - a[i - 1] < b[i] - b[i - 1]) return true;
|
|
if (a[i] - a[i - 1] > b[i] - b[i - 1]) return false;
|
|
}
|
|
return false;
|
|
}
|
|
} arr[362881];
|
|
int main()
|
|
{
|
|
int T, n, k;
|
|
scanf("%d", &T);
|
|
while (T--)
|
|
{
|
|
scanf("%d%d", &n, &k);
|
|
if (n <= 9)
|
|
{
|
|
for (int i = 0; i < n; i++) a[i] = i + 1;
|
|
int cnt = 0;
|
|
do
|
|
{
|
|
memcpy(arr[cnt].a, a, n << 2);
|
|
arr[cnt].n = n;
|
|
cnt++;
|
|
/*for (int i = 0; i < n; i++)
|
|
printf("%2d%c", a[i], " \n"[i == n - 1]);
|
|
printf(" ");
|
|
for (int i = 1; i < n; i++)
|
|
printf("%2d%c", a[i] - a[i - 1], " \n"[i == n - 1]);
|
|
putchar('\n');*/
|
|
} while (next_permutation(a, a + n));
|
|
sort(arr, arr + cnt);
|
|
/*
|
|
for (int i = 0; i < cnt; i++)
|
|
{
|
|
auto a = arr[i].a;
|
|
for (int i = 0; i < n; i++)
|
|
printf("%2d%c", a[i], " \n"[i == n - 1]);
|
|
printf(" ");
|
|
for (int i = 1; i < n; i++)
|
|
printf("%2d%c", a[i] - a[i - 1], " \n"[i == n - 1]);
|
|
putchar('\n');
|
|
}*/
|
|
auto a = arr[k - 1].a;
|
|
for (int i = 0; i < n; i++) printf("%d%c", a[i], " \n"[i == n - 1]);
|
|
}
|
|
else
|
|
{
|
|
a[0] = n;
|
|
for (int i = 1; i < n; i++) a[i] = i;
|
|
int cnt = 0;
|
|
do
|
|
{
|
|
//memcpy(arr[cnt].a, a, n << 2);
|
|
//arr[cnt].n = n;
|
|
cnt++;
|
|
if (cnt == k) break;
|
|
} while (next_permutation(a, a + n));
|
|
for (int i = 0; i < n; i++) printf("%d%c", a[i], " \n"[i == n - 1]);
|
|
}
|
|
}
|
|
return 0;
|
|
} |