Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting
of n distinct integers from range from 1 to n.
We say that this permutation maps value 1 into the value p1,
value 2 into the value p2 and
so on.

Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a sequence of numbers such that each element
of this sequence is being mapped into the next element of this sequence (and the last element of the cycle is being mapped into the first element of the cycle). The cyclic representation is a
representation of p as a collection of cycles forming p.
For example, permutationp = [4, 1, 6, 2, 5, 3] has a cyclic representation that
looks like (142)(36)(5) because 1 is replaced by 4, 4 is replaced by 2, 2 is replaced by 1, 3 and 6 are swapped, and 5 remains in place.

Permutation may have several cyclic representations, so Kyoya defines the standard cyclic representation of a permutation as follows. First, reorder the elements within each cycle so the largest
element is first. Then, reorder all of the cycles so they are sorted by their first element. For our example above, the standard cyclic representation of [4, 1, 6, 2, 5, 3] is (421)(5)(63).

Now, Kyoya notices that if we drop the parenthesis in the standard cyclic representation, we get another permutation! For instance,[4, 1, 6, 2, 5, 3] will
become [4, 2, 1, 5, 6, 3].

Kyoya notices that some permutations don't change after applying operation described above at all. He wrote all permutations of length nthat
do not change in a list in lexicographic order. Unfortunately, his friend Tamaki Suoh lost this list. Kyoya wishes to reproduce the list and he needs your help. Given the integers n and k,
print the permutation that was k-th on Kyoya's list.

Input

The first line will contain two integers nk (1 ≤ n ≤ 50, 1 ≤ k ≤ min{1018, l} where l is
the length of the Kyoya's list).

Output

Print n space-separated integers, representing the permutation that is the answer for the question.

Sample test(s)
input
4 3
output
1 3 2 4
input
10 1
output
1 2 3 4 5 6 7 8 9 10
Note

The standard cycle representation is (1)(32)(4), which after removing parenthesis gives us the original permutation. The first permutation on
the list would be [1, 2, 3, 4], while the second permutation would be [1, 2, 4, 3].

题意:

给出n,k。代表有包括1~n的一个数组。通过对这些数进行一些排列,对于当中的一个序列,第i个位置会指向第a[i]个位置,如此便会形成一些环,将这些环合并成一组。按大到小排序,然后对于形成的多组而言,依照每一组开头数字的大小从小大大排序,形成一个新的序列

而对于这些序列而言,当中有一些序列依照题意的分类排序方法得到的新序列是与本身相等的,如今要求这些序列中的第k个是多少。k不会超过这样的序列的总数

思路:

对于这样的类型的序列,那么必定是交换相邻的两个。并且已经交换过了的是不能再交换了,而当中数量又与斐波那契数有关系

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <list>
#include <algorithm>
#include <climits>
using namespace std; #define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 100005
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x)
const int mod = 1e9+7; LL n,k;
LL a[55]; int main()
{
LL i,j;
a[0] = a[1] = 1;
for(i = 2;i<=50;i++)
{
a[i] = a[i-1]+a[i-2];
}
scanf("%I64d%I64d",&n,&k);
LL c1 = 1,c2 = 2;
while(n>0)
{
if(k>a[n-1])
{
printf("%I64d %I64d ",c2,c1);
k-=a[n-1];
n-=2;
c2+=2;
c1+=2;
}
else
{
printf("%I64d ",c1);
n--;
c1++;
c2++;
}
}
printf("\n"); return 0;
}

Codeforces554D:Kyoya and Permutation的更多相关文章

  1. Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造

    B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  2. Codeforces Round #309 (Div. 2) -D. Kyoya and Permutation

    Kyoya and Permutation 这题想了好久才写出来,没看题解写出来的感觉真的好爽啊!!! 题目大意:题意我看了好久才懂,就是给你一个序列,比如[4, 1, 6, 2, 5, 3],第一个 ...

  3. codeforces 553B B. Kyoya and Permutation(找规律)

    题目链接: B. Kyoya and Permutation time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  4. Codeforces 553B Kyoya and Permutation

    problem 题意 本题题意不太easy看懂. 给定一个序列,我们能够把这个序列变成一些循环置换的和.然而这样的置换的方法是不止一种的.我们定义一种standard cyclic represent ...

  5. 【Codeforces】【#295】【Div.1】

    嘛,一直以来蒟蒻都没怎么打过CF……现在还是蓝名狗……今天跟着zyf打了一场virtual,果断一题滚粗

  6. Codeforces Round #309 (Div. 1)

    A. Kyoya and Colored Balls 大意: 给定$k$种颜色的球, 第$i$种颜色有$c_i$个, 一个合法的排列方案满足最后一个第$i$种球的下一个球为第$i+1$种球, 求合法方 ...

  7. Permutation Sequence

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

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

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

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

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

随机推荐

  1. If-Modified-Since页面是否更新

    第一次先请求某个网页,抓取到本地,假设文件名为 a.html.这时文件系统有个文件的修改时间. 第二次访问网页,如果发现本地已经有了 a.html,则向服务器发送一个 If-Modified-Sinc ...

  2. Function 详解(一)

    一直想写一系列关于javascript的东西,可惜从申请博客以来就一直抽不出时间来好好写上一番,今天终于熬到周末,是该好好整理一下,那么先从声明函数开始吧; 总所周知,在javascript中有匿名函 ...

  3. Java Thread.join()详解(转)

    (1)join方法是可以中断的(2)在线程joiner在另一个线程t上调用t.join(),线程joiner将被挂起,直到线程t结束(即t.isAlive()返回为false)才恢复 package ...

  4. Otacle表查询

    1    查询表结构       语法:desc 表      2    查询全部列       语法:select * from 表名      3    查询指定列       语法:select ...

  5. JMS学习(三)ActiveMQ Message Persistence(转)

    1,JMS规范支持两种类型的消息传递:persistent and non-persistent.ActiveMQ在支持这两种类型的传递方式时,还支持消息的恢复.中间状态的消息(message are ...

  6. nginx做下载限速

    nginx做下载限速-szszszsz-ChinaUnix博客 nginx做下载限速 2009-12-25 14:34:57 分类: 系统运维 nginx做下载服务器,在性能上满足需求.自带limit ...

  7. HDU 3488Tour(流的最小费用网络流)

    职务地址:hdu3488 这题跟上题基本差点儿相同啊... . 详情请戳这里. 另外我认为有要改变下代码风格了..最终知道了为什么大牛们的代码的变量名都命名的那么长..我决定还是把源点与汇点改成sou ...

  8. python语言学习6——python基础

    Python是一种计算机编程语言. 以#开头的语句是注释,注释是给人看的,可以是任意内容 其他每一行都是一个语句,当语句以冒号:结尾时,缩进的语句视为代码块. Python程序是大小写敏感的,如果写错 ...

  9. 关于windows系统影子账户的问题

    在这之前,需要大家了解几个问题,一个是SID,一个是账号的F值. Windows账户的SID 在Windows系统中,系统会为每个用户账户建立一个唯一的安全标识符(Security Identifie ...

  10. poj 1198 hdu 1401 搜索+剪枝 Solitaire

    写到一半才发现能够用双向搜索4层来写,但已经不愿意改了,干脆暴搜+剪枝水过去算了. 想到一个非常水的剪枝,h函数为  当前点到终点4个点的最短距离加起来除以2.由于最多一步走2格,然后在HDU上T了, ...