Codeforces554D:Kyoya and Permutation
来源:互联网 发布:对网络安全技术的认识 编辑:程序博客网 时间:2024/06/08 17:50
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.
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).
Print n space-separated integers, representing the permutation that is the answer for the question.
4 3
1 3 2 4
10 1
1 2 3 4 5 6 7 8 9 10
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
- Codeforces 553B Kyoya and Permutation
- Codeforces 553B Kyoya and Permutation
- Codeforces 553 B. Kyoya and Permutation
- Codeforces 553B Kyoya and Permutation 排列问题
- codeforces 553B Kyoya and Permutation 构造+规律
- CodeForces 553B Kyoya and Permutation(找规律)
- codeforces #309 553B B. Kyoya and Permutation(斐波那契数)
- Codeforces Round #309 (Div. 1) B. Kyoya and Permutation(数学)
- Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 找规律
- Codeforces554A:Kyoya and Photobooks
- A. Kyoya and Photobooks
- Codeforces Round #309 (Div. 2) D - Kyoya and Permutation ,和dp相关的xjb搞的题
- Codeforces 554A Kyoya and Photobooks
- codeforces 553 A Kyoya and Colored Balls
- Codeforces 553A Kyoya and Colored Balls
- #309 (div.2) A. Kyoya and Photobooks
- CodeForces-554A Kyoya and Photobooks
- Openshift V3简介 - Docker 应用平台
- 【密钥算法】Java加密技术(一)---BASE64、MD5、SHA、HMAC数据加密算法
- 自动布局之autoresizingMask使用详解(Storyboard&Code)
- iOS开发系列--让你的应用“动”起来
- VS2013+Python+OpenCV的配置
- Codeforces554D:Kyoya and Permutation
- mysql中进行md5加密
- C语言打印100以内的质数
- wordpress独立下载插件插件 ordown微互联出品
- HDOJ 题目2670 Girl Love Value(01背包)
- for dg test
- Object类中的equals(Object obj) 和 操作符“==”的区别
- 第四节GCC常用的编译命令
- JAVA对ArrayList排序