Problem 3011 --permutation 1

3011: permutation 1

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $2$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
A sequence of length nn is called a permutation if and only if it's composed of the first nn positive integers and each number appears exactly once. 

Here we define the "difference sequence" of a permutation p1,p2,…,pnp1,p2,…,pn as p2−p1,p3−p2,…,pn−pn−1p2−p1,p3−p2,…,pn−pn−1. In other words, the length of the difference sequence is n−1n−1 and the ii-th term is pi+1−pipi+1−pi 

Now, you are given two integers N,KN,K. Please find the permutation with length NNsuch that the difference sequence of which is the KK-th lexicographically smallest among all difference sequences of all permutations of length NN.
The first line contains one integer TT indicating that there are TT tests. 

Each test consists of two integers N,KN,K in a single line. 

1≤T≤401≤T≤40 

2≤N≤202≤N≤20 

1≤K≤min(104,N!)
For each test, please output NN integers in a single line. Those NN integers represent a permutation of 11 to NN, and its difference sequence is the KK-th lexicographically smallest.
7
3 1
3 2
3 3
3 4
3 5
3 6
20 10000
3 1 2
3 2 1
2 1 3
2 3 1
1 2 3
1 3 2
20 1 2 3 4 5 6 7 8 9 10 11 13 19 18 14 16 15 17 12

推荐代码 查看3011 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$70 $ms] 淡意的温柔 590714 2020-06-05 08:43:52
内存最少[$10692 $KB] 淡意的温柔 590714 2020-06-05 08:43:52
第一AC 淡意的温柔 590714 2020-06-05 08:43:52
第一挑战 淡意的温柔 590713 2020-06-05 08:43:30

赛题来源/所属竞赛 2019 Multi-University Training Contest 5 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛