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 ...
随机推荐
- git关联github远程仓库的问题
git关联github远程仓库的时候,报fatal: remote origin already exists. 导致这个问题原因可能是之前关联的时候关联错了,再次关联就不行了. 解决办法是: 1.将 ...
- Python实现批量执行华为交换机脚本
#!/usr/bin/python3 # -*- coding:utf-8 -*- import paramiko import time ssh = paramiko.SSHClient() key ...
- webpack e6转化成es5 配置方法
方法一: https://www.babeljs.cn/setup#installation 按照babel官方的配置配 方法二: https://www.jianshu.com/p/ce28cedd ...
- Spring Task 任务调度(定时器)
1.任务调度SpringTask 1.1什么是任务调度 在企业级应用中,经常会制定一些“计划任务”,即在某个时间点做某件事情,核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作.常见的 ...
- Java 5种单例模式
/*单例模式: 指某个类中只能存在一个对象实例,并且该类中只提供一个取得其对象实例的方法 优点:减少系统性能开销 应用场景:网站的计数器,任务管理器,回收站等*/ //单例模式1 -- 静态内部类 ...
- P3958奶酪
这个题是2017noip提高组的真题,是一个深度搜索题,得分轨迹:10-80-100pts. 在三维空间里,存在可能连通的洞(半径r),问是否可以通过这些洞从底部到达顶部.一开始我联想到了01迷宫,以 ...
- SGU 521 North-East ( 二维LIS 线段树优化 )
521. "North-East" Time limit per test: 0.5 second(s)Memory limit: 262144 kilobytes input: ...
- django2.0url的变动
WARNINGS:?: (urls.W001) Your URL pattern '^$' uses include with a route ending with a '$'. Remove th ...
- htpwdScan — 一个简单的HTTP暴力破解、撞库攻击脚本
李姐姐之前跟我们分享了子域名枚举工具subDomainBrute<subDomainsBrute — 改进渗透测试时暴力枚举子域名的python脚本>,这回带给我们htpwdScan ht ...
- Android 在同一个手机上安装多个相同的apk,便于调试
Android studio 在同一个手机上安装多个相同的apk 原文地址:http://yj.itrydo.com/posts/iKJryXL9zkfSGRTZk 先看效果: 1.在我使用ecsli ...