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的更多相关文章

  1. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  2. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  3. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  4. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  6. 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 ...

  7. UVA11525 Permutation[康托展开 树状数组求第k小值]

    UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...

  8. 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 ...

  9. Permutation

    (M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II

  10. Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

随机推荐

  1. 关于SQL连接语句中的Integrated Security=SSPI/ture/false

    解决方法:即:Security Support Provider Interface设置Integrated Security为 True 的时候,连接语句前面的 UserID, PW 是不起作用的, ...

  2. 华南理工大学 “三七互娱杯” G HRY and tree

    https://ac.nowcoder.com/acm/contest/874/G 题目大意:对于一个连通图,现在定义两个点的贡献为连接两点的路径上最大的权值 求任意两个点贡献的和 这个题看懂花了我很 ...

  3. [19/09/19-星期四] Python中的字典和集合

    一.字典 # 字典 # 使用 {} 来创建字典 d = {} # 创建了一个空字典 # 创建一个保护有数据的字典 # 语法: # {key:value,key:value,key:value} # 字 ...

  4. echart 柱状图 两个纵轴坐标 刻度不一样

    在使用echart的过程中, 有的时候柱状图会使用两个纵坐标, 如果两个纵坐标的最大值是一样的还好,这样刻度也会一样. 但是多数情况下最大值是不一样的, 这样就造成了,刻度线很乱,显示不均匀. 解决办 ...

  5. java 数组详细介绍

    一.概述 数组(Array),是多个相同类型数据按一定顺序排列的集合,并使用一个名字命名,并通过编号的方式对这些数据进行统一管理 数组常见概念: 数组名, 下标(或索引), 元素, 数组的长度 数组本 ...

  6. 关系型数据库为什么喜欢使用B+树作为索引结构? (转)

    问题1. 数据库为什么要设计索引? 图书馆存了1000W本图书,要从中找到<架构师之路>,一本本查,要查到什么时候去? 于是,图书管理员设计了一套规则: (1)一楼放历史类,二楼放文学类, ...

  7. ASP.NET服务器控件Menu

    http://www.cnblogs.com/huc87/archive/2009/04/05/1429831.html ASP.NET服务器控件Menu 1.       ASP.NET 服务器控件 ...

  8. application详解

    Application对象是HttpApplicationState类的一个实例,Application状态是整个应用程序全局的.本文主要详细介绍Application对象的用法. 一.全局应用程序类 ...

  9. sass和less的对比

    );  <  { ;  {   {     ; } ); } ); } );  // if 条件  @dr: if(@my-option = true, {     button {       ...

  10. Android 点击跳转到蓝牙设置界面

    不再重写一遍了,看csdn: https://blog.csdn.net/qq_42866164/article/details/101353709