problem

题意

  • 本题题意不太easy看懂。

    给定一个序列,我们能够把这个序列变成一些循环置换的和。然而这样的置换的方法是不止一种的。我们定义一种standard cyclic representation,即每一个循环置换中最大的数都在第一个。把得到的循环置换的括号去掉。我们能够得到一个新的序列。

    定义一个序列,使得它变成置换后再去掉括号得到的新序列和原序列同样,那么称这样的序列是稳定的。给定一个n(序列长度)和k。要求求出全部稳定序列按字典序排序后的第k大序列。


思路

  • 首先我们能够证明。稳定序列是具有一定性质的。第一。1,2,3...n这样的序列是稳定序列。

    第二,全部的稳定序列都是由1,2,3...n这样的序列经过相邻的数交换得来的。而且每一个数仅仅能被交换一次。

  • 这是由于。稳定的置换中,每一个循环置换的长度不可能超过2。

    由于长度为3的循环置换就已经不可能找出了,故长度大于4的也不可能找出。

  • 有了这个性质,能够推知,对于长度为n的序列,共同拥有fib[n]种稳定序列。
  • 我们对每一位进行推断。假设当前的k<fib[n-i]说明当前位无需发生改变,否则就交换当前位和下一位,而且在k中减去不交换的序列数,即fib[n-i]。最后输出答案就可以。

AC代码

/*written by znl1087*/
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL fib[51],k;
int n;
int ans[51];
int main()
{
fib[0] = fib[1] = 1LL;
for(int i=2;i<=51;i++)fib[i] = fib[i-1]+fib[i-2];
cin>>n>>k;
k--;
for(int i=1;i<=n;i++)ans[i] = i;
for(int i=1;i<=n;){
if(k < fib[n-i])
i++;
else{
swap(ans[i],ans[i+1]);
k-=fib[n-i];
i+=2;
}
}
for(int i=1;i<=n;i++)cout<<ans[i]<<(i == n? '\n':' ');
return 0;
}

Codeforces 553B Kyoya and Permutation的更多相关文章

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

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

  2. 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/ ...

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

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

  4. Codeforces A. Kyoya and Colored Balls(分步组合)

    题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT)

    [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT) 题面 给出一个\(n\)个点\(m\)条边的有向图(可能有环),走每条边需要支付一个价格\(c_i ...

  6. Codeforces554D:Kyoya and Permutation

    Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct ...

  7. Codeforces 691D Swaps in Permutation

    Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Prac ...

  8. Codeforces 500B. New Year Permutation[连通性]

    B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

随机推荐

  1. python几个重要的函数(lambda,filter,reduce,map,zip)

    一.匿名函数lambda lambda argument1,argument2,...argumentN :expression using arguments 1.lambda是一个表达式,而不是一 ...

  2. [ Mariadb ] 记录一次MySQL数据库时区的问题

    操作系统:Centos 7数据库:5.5.52-MariaDB 根本问题:由于系统时区不对,造成数据库的时区和数据的时间不正确. 处理办法: # 查看系统时区, [root@mongodb ~]# t ...

  3. 【SQL】数据库更新

    1.插入 INSERT INTO R(A1,A2,...An) VALUES(v1, v2, ...,vn) 如果插入了所有属性,并且按照定义的顺序给出,可以省略(A1,A2,...An) 可以只插入 ...

  4. Solidity 文档--目录

    Solidity是一种语法类似JavaScript的高级语言.它被设计成以编译的方式生成以太坊虚拟机代码.在后续内容中你将会发现,使用它很容易创建用于投票.众筹.封闭拍卖.多重签名钱包等等的合约. 注 ...

  5. KDJ金叉测试

    # -*- coding: utf-8 -*- import os import pandas as pd # ========== 遍历数据文件夹中所有股票文件的文件名,得到股票代码列表stock_ ...

  6. PYTHON代理IP

    import urllib.request url = 'http://www.whatismyip.com.tw/' proxy_support = urllib.request.ProxyHand ...

  7. HBuilder开发移动App——manifest.json文件解析

    以前做过Android App开发,对于各项配置都是在AndroidManifest.xml文件中完成的,包括权限的设定.图标.标签.App的名字.Activity注册等等 使用HBuilder开发移 ...

  8. APP中常见上下循环滚动通知的简单实现,点击可进入详情

    APP中常见上下循环滚动通知的简单实现,点击可进入详情 关注finddreams博客,一起分享一起进步!http://blog.csdn.net/finddreams/article/details/ ...

  9. AC日记——codeforces Ancient Berland Circus 1c

    1C - Ancient Berland Circus 思路: 求出三角形外接圆: 然后找出三角形三条边在小数意义下的最大公约数; 然后n=pi*2/fgcd; 求出面积即可: 代码: #includ ...

  10. The number of steps(概率dp)

    Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one r ...