Codeforces 553B Kyoya and Permutation
题意
- 本题题意不太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的更多相关文章
- codeforces 553B B. Kyoya and Permutation(找规律)
题目链接: B. Kyoya and Permutation time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- 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/ ...
- Codeforces Round #309 (Div. 2) -D. Kyoya and Permutation
Kyoya and Permutation 这题想了好久才写出来,没看题解写出来的感觉真的好爽啊!!! 题目大意:题意我看了好久才懂,就是给你一个序列,比如[4, 1, 6, 2, 5, 3],第一个 ...
- Codeforces A. Kyoya and Colored Balls(分步组合)
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT)
[Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT) 题面 给出一个\(n\)个点\(m\)条边的有向图(可能有环),走每条边需要支付一个价格\(c_i ...
- Codeforces554D:Kyoya and Permutation
Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct ...
- Codeforces 691D Swaps in Permutation
Time Limit:5000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Prac ...
- Codeforces 500B. New Year Permutation[连通性]
B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
随机推荐
- css3带你实现酷炫效果
css3 私有前缀 -webkit- chrome/safari等webkit内核浏览器 -moz- firfox -o- opera -ms- IE css3 盒子模型 box-sizing 值co ...
- WPF中使用WPFMediaKit视频截图案例
前台 代码: <Window x:Class="WpfAppWPFMediaKit.MainWindow" xmlns="http://schemas.micros ...
- pandas基础学习
1.导入两个数据分析重要的模块import numpy as npimport pandas as pd2.创建一个时间索引,所谓的索引(index)就是每一行数据的id,可以标识每一行的唯一值dat ...
- k8s 组件架构
一.整体架构 kubernetes分为 master节点和工作节点,前者是管理节点,后者是容器运行的节点.其中master节点主要有3个重要组件,分别是APIServer,sheduler和contr ...
- mysql 如何提高批量导入的速度
mysql 如何提高批量导入的速度 最近一个项目测试,有几个mysql数据库的表数据记录达到了几十万条,在搭建测试环境 导入 测试数据时,十分慢.在网上搜索了一下,有下面一些方法可以加快mysql数据 ...
- IE67下去掉input边框
除了 border:none;之外 需要 border-color:#fff; overflow:hidden;
- /usr/bin/env: php: No such file or directory 【xunsearch demo项目体验】【已解决】
出现这个问题的原因是/usr/local/bin 或 /usr/bin 下面没有php可执行文件 解决办法: 建立一条硬链接 ln /path/to/bin/php /usr/local/bin/p ...
- 详解Oracle数据货场中三种优化:分区、维度和物化视图
转 xiewmang 新浪博客 本文主要介绍了Oracle数据货场中的三种优化:对分区的优化.维度优化和物化视图的优化,并给出了详细的优化代码,希望对您有所帮助. 我们在做数据库的项目时,对数据货场的 ...
- Codeforces Round #442 A Alex and broken contest【字符串/常量数组/string类】
A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- IBM-Club IntelliJ IDEA 开发环境的安装
各位小伙伴初次使用IDE,可能还是有许多疑惑,因此这篇博客阿鲁给大家分享一下,自己平时是如何安装IntelliJ IDEA的 1.原料:安装包,直接百度搜索进入官网下载 记住是Ultimate版本呦, ...