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 ...
随机推荐
- Spring Boot 为什么这么火?(二)
Spring Boot 的火 网上连载了 Spring Boot 系列文章,没想到这一开始便与 Spring Boot 深度结缘. 技术社区 Spring Boot 的文章越来越多:Spring Bo ...
- RHEL 无图形界面安装oracle 11gr2
RHEL7.3 无图形界面安装oracle 11gr2 使用纯命令安装方式.提供RHEL全量系统镜像. 1.oracle官方下载地址:https://www.oracle.com/techne ...
- [HDU 3712] Fiolki (带边权并查集+启发式合并)
[HDU 3712] Fiolki (带边权并查集+启发式合并) 题面 化学家吉丽想要配置一种神奇的药水来拯救世界. 吉丽有n种不同的液体物质,和n个药瓶(均从1到n编号).初始时,第i个瓶内装着g[ ...
- MySQL explain,Extra分析(转)
explain结果中有一个Extra字段,对分析与优化SQL有很大的帮助 数据准备: create table user ( id int primary key, name varchar(20), ...
- HDU 2196 Computer( 树上节点的最远距离 )
Computer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- ASP.net解析JSON
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- vue梳理(2)
-app.vue作为根组件被挂载到index.html文件里,其他的所有组件都是在app.vue组件里做文章. 展示给用户的就是app.vue里的内容,你觉得删的没有内容了但实际还有很多是因为什么呢? ...
- Java List对象集合按对象属性分组、分组汇总、过滤等操作示例
import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Col ...
- iOS之Run Loop详解
转自标哥的技术博客(www.henishuo.com) 前言 做了一年多的IOS开发,对IOS和Objective-C深层次的了解还十分有限,大多还停留在会用API的级别,这是件挺可悲的事情.想学好一 ...
- 富文本编辑器Ueditor
一.大概使用: 官网:http://ueditor.baidu.com/website/download.html 使用:[参考index.html] 3.1 引入ueditor的js <scr ...