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 ...
随机推荐
- 使用 PC 做 FTP/TFTP 服务器,上传和下载文件
使用PC做TFTP服务器,上传和下载文件需要用到一个工具软件,IPOP,可百度下载. 1.在桌面新建一个空闲的文件夹,作为TFTP服务器的存储位置,然后打开IPOP软件,开启服务. 图片中 编号3 的 ...
- netstat -anop|more 查看网络队列
nux下netstat --timers / -o详解及keepalive相关 第一列,一般有一下几种状态: keepalive - #表示是keepalive的时间计时 on - #表示是重发(re ...
- [转帖]同事推荐的的aira2
Windows系统安装最新版Aria2客户端及使用教程 https://www.moerats.com/archives/519/ 改天学习一下. 说明:之前都是说的在Linux VPS服务器上安装A ...
- oracle跟SQL Server 2005 的区别
Oracle与Sql server的区别 一直搞不明白Oracle数据库和sql server的区别,今天我特意查资料把他们的区别整理出来 Oracle数据库:Oracle Database,又名 ...
- 【6.10校内test】T1 FBI树
FBI树[题目链接] 感觉我超废. MY SOLUTION: 我的想法其实也是很简单的,递归的去做,因为最后要求输出FBI的后序遍历,也就是左右头,我的方法是递归存字符数组,(按照与后序遍历完 ...
- exosip2 build
Build eXosip on Win 1. download exosip http://savannah.nongnu.org/projects/exosip/ 2. download libc ...
- spark性能调优03-shuffle调优
1.开启map端输出文件的合并机制 1.1 为什么要开启map端输出文件的合并机制 默认情况下,map端的每个task会为reduce端的每个task生成一个输出文件,reduce段的每个task拉取 ...
- P3190 [HNOI2007]神奇游乐园
传送门 第一道插头 $dp$ 由于讲不清楚所以假装各位早就会插头 $dp$ 了 首先要的是一个闭合回路,所以可以用括号表示法表示状态,然后大力分类讨论 $1.$ 没有右插头和下插头 那么我们可以啥也不 ...
- js实现404页面倒计时跳转
<script type="text/javascript"> (function(){ var i=5,timer=null,number=document.getE ...
- TMS320F28335——SCI串口
一.IO配置 以SCIA为例:使用的是GPIO35--SCITXDA GPIOA36--SCIRXDA 使用寄存器: GPBPUD :设置上拉 GPIO32-GPIO63 对应位0 使能上 ...