B. Kyoya and Permutation

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/553/problem/B

Description

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, permutation p = [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 n that 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 n, k (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 Input

4 3

Sample Output

1 3 2 4

HINT

题意

cycle,就是不在同一个位置的数,会成为一个圈

每个cycle从大到小排序,所有cycle按第一个元素从大到小排序

排序完了以后跟原来的序列不变就是合法

然后让你输出第k大的合法数组

题解:

dp[i] = dp[i - 1] + dp[i - 2]

比如1号位,可以放1

1号位,也可以放2,如果放2

那么考虑2号位

显然不能比2大

那就只能放1了

1号位放3以上的都不行

知道合法种类数有第n个fib数个数之后,构造方法就很显然了

代码

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2000001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll c[]={,,},k;
int n,a[];
main()
{
for(int i=;i<;i++)
c[i]=c[i-]+c[i-];
cin>>n>>k;
for(int i=;i<=n;)
{
if (k>c[n-i])
{
k-=c[n-i];
a[i]=i+;
a[i+]=i;i+=;
}
else
{
a[i]=i;
i++;
}
}
for(int i=;i<=n;i++)
printf("%d ",a[i]);
}

Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造的更多相关文章

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

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

  2. 找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks

    题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...

  3. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合

    C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  4. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题

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

  5. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

  6. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks【*组合数学】

    A. Kyoya and Photobooks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  7. 贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up

    题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...

  8. Codeforces Round #309 (Div. 1)

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

  9. C. Kyoya and Colored Balls(Codeforces Round #309 (Div. 2))

    C. Kyoya and Colored Balls Kyoya Ootori has a bag with n colored balls that are colored with k diffe ...

随机推荐

  1. 基于XMPP协议的手机多方多端即时通讯方案

    一.开发背景 1.国际背景 随着Internet技术的高速发展,即时通信已经成为一种广泛使用的通信方式.1996年Mirabilis公司推出了世界上第一个即时通信系统ICQ,不到10年间,即时通信(I ...

  2. Php 笔记4-----php 细节知识

    从 php5开始  php.ini  register_globals参数为OFF  ,禁止全局变量. 以前的情况下,  全局变量是默认为On的 , 所以,浏览器的表单中控件,会自动根据name在服务 ...

  3. asp.net使用httphandler打包多CSS或JS文件以加快页面加载速度

    介绍 使用许多小得JS.CSS文件代替一个庞大的JS或CSS文件来让代码获得更好的可维 护性,这是一个很好的实践.但这样做反过来却损失了网站的性能.虽然你应该将你的Javascript代码写在小文件中 ...

  4. 设计模式 命令-Command

    命令-Command 当要向不同类的对象发出相同的请求时,可以将接收者和他的动作封装进一个命令对象.这样调用者只和命令产生依赖.而不会和众多的接收者发生依赖. Head First例子 要设计一款遥控 ...

  5. Fedora20 和ubuntu 14.04 chrome标签中文乱码

    作为两个流行的桌面发行版本,Fedora和ubuntu最新版本都存在chrome标签中文乱码问题. 下面是解决办法,都来自百度贴吧. 1.ubuntu 系列: 解决办法就是: 编辑/etc/fonts ...

  6. linux nginx安装(转载)

    1.linux 下面安装 1.下载 pcre-8.10.tar.gz  nginx-1.1.1.tar.gz 2.安装 pcre 让nginx支持rewrite pcre-8.10.tar.gz  上 ...

  7. 第二百三十六天 how can I 坚持

    太冷了,羽绒服没帽子,冻的耳朵疼. 她今天没有上班,原来是调休了. 其实应该是想到点啥,就应该写下,到晚上写就又忘了,什么都不记得了,这就是个需求吧. 睡觉.

  8. C++builder XE10 终于支持类内变量初始化了

    Win32终于支持类内变量初始化了,C++11 用bcc32C编译器  llvm CLang.还支持Unicode 中文汉字 变量名. 用经典的bcc32编译还是不支持! class TPerson ...

  9. 2 weekend110的HDFS的JAVA客户端编写 + filesystem设计思想总结

    HDFS的JAVA客户端编写  现在,我们来玩玩,在linux系统里,玩eclipse 或者, 即,更改图标,成功 这个,别慌.重新换个版本就好,有错误出错是好事. http://www.eclips ...

  10. [转]模拟HttpContext 实现ASP.NET MVC 的单元测试

    众所周知 ASP.NET MVC 的一个显著优势即可以很方便的实现单元测试,但在我们测试过程中经常要用到HttpContext,而默认情况下单元测试框架是不提供HttpContext的模拟的,本文通过 ...