permutation 1
permutation 1
#include<bits/stdc++.h>
using namespace std;
int A[];
void init()
{
for(int i=; i<=; i++)A[i]=i;
}
int N;
struct Nod
{
int A[],B[];
};
Nod T[];
bool cmp(Nod A,Nod B)
{
int n=N-;
if(n>)n=;
for(int i=; i<n; i++)
{
if(A.B[i]!=B.B[i])
return(A.B[i]<B.B[i]); }
}
void work()
{
long long K;
int cnt=;
init();
scanf("%d%lld",&N,&K);
if(N<=)
{
do
{
for(int i=; i<N; i++)
{
T[cnt].A[i]=A[i+];
}
for(int i=; i<N-; i++)
{
T[cnt].B[i]=T[cnt].A[i+]-T[cnt].A[i];
}
cnt++; }
while(next_permutation(A+,A+N+)); sort(T,T+cnt,cmp);
for(int i=; i<N; i++)
{
cout<<T[K-].A[i]<<(i==N-?'\n':' ');
} }
else
{
do
{
if(N>)
T[cnt].A[]=N-;
else T[cnt].A[]=N;
for(int i=N-; i<N; i++)
{
T[cnt].A[i-N+]=A[i];
}
for(int i=; i<; i++)
{
//cout<<T[cnt].A[i]<<'\n';
T[cnt].B[i]=T[cnt].A[i+]-T[cnt].A[i];
}
cnt++; }
while(next_permutation(A+N-,A+N));//cout<<cnt<<'\n';
sort(T,T+cnt,cmp);
if(N>)
cout<<N<<' ';
for(int i=;i<=N-;i++){
cout<<i<<' ';
}
for(int i=; i<; i++)
{
cout<<T[K-].A[i]<<(i==?'\n':' ');
}
}
}
int main()
{
freopen("1.in","r",stdin);
int _T;
scanf("%d",&_T);
while(_T--)
{
work();
} }
permutation 1的更多相关文章
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Next Permutation 下一个排列
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- Leetcode 60. Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- UVA11525 Permutation[康托展开 树状数组求第k小值]
UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...
- Permutation test: p, CI, CI of P 置换检验相关统计量的计算
For research purpose, I've read a lot materials on permutation test issue. Here is a summary. Should ...
- Permutation
(M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II
- Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
随机推荐
- unittest中的断言方法
方法 用途 assertEqual(a,b) a=b assertNotEqual(a,b) a!=b assertTrue(x) x为True assertFa ...
- 文档压缩 | gzip、bzip2、xz
6.文档的压缩与打包 Linux下常见后缀名所对应的的压缩工具 .gz 表示由gzip压缩工具压缩的文件 .bz2 表示由bzip2压缩工具压缩的文件 .tar 表示由tar打包程序打包的文件(tar ...
- 大二 Java上学期总结
一学期的Java学习结束了,这学期对程序语言的理解更深了,首先感谢李津老师的教导,这学期收获挺多的,不像上学期,这学期没有任何缺课表现,希望之后的语言程序学习会更加努力. 突然感觉Java的学习如此之 ...
- Dubbo 序列化协议 5 连问,你接得住不?
1)dubbo 支持哪些通信协议? 2)支持哪些序列化协议? 3)说一下 Hessian 的数据结构? 4)PB 知道吗? 5)为什么 PB 的效率是最高的? 面试官心理分析 上一个问题,说说 dub ...
- 使用Docker部署Spring-Boot+Vue博客系统
在今年年初的时候,完成了自己的个Fame博客系统的实现,当时也做了一篇博文Spring-boot+Vue = Fame 写blog的一次小结作为记录和介绍.从完成实现到现在,也断断续续的根据实际的使用 ...
- Prometheus 2.14.0 新特性
Prometheus 2.14.0 现在(2019.11.11)已经发布,在上个月的 2.13.0 之后又进行了一些修正和改进. 这次最大的新功能是基于 React 的新 UI,与现有 UI 大体相同 ...
- jmeter性能测试抛除工具用命令测试的方法
1.我们有时会遇到那种图片或文件大的传输数据,容易将jmeter测试工具卡死,这个时候就需要抛除测试工具,直接用命令进行测试(window和linux都适用) 2.首先在jmeter工具上把性能测试脚 ...
- vue项目1-pizza点餐系统6-路由精讲之复用router-view
1.在主组件展示二级路由的组件内容,在App.vue中添加 <br> <div class="container"> <!-- row 行排列 --& ...
- CentOS7 添加新用户并授权 root 权限
参考文章:CentOS 7中添加一个新用户并授权 # root 用户操作 $ 普通用户操作 创建用户 # adduser USERNAME # passwd USERNAME (输入密码) 授权 ro ...
- Nginx cpu亲和性调整
意义 Nginx默认没有开启利用多核cpu,我们可以通过worker_processes指令来启动多个worker,但是worker最终运行在哪些cpu核上是系统层进行调度的:我们可以通过增加work ...