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.紧接着是一个 ...
随机推荐
- 【bzoj3744】GTY的妹子序列
大力分块+树状数组+主席树…… #include<bits/stdc++.h> #define N 50005 #define pa pair<int,int> #define ...
- 【 Nginx 】proxy_cache 模块的使用记录
部署环境:nginx + tomcat 同一台服务器. 通过nginx反向代理tomcat. 配置如下: user www www; worker_processes auto; error_log ...
- C# 正则表达式判断IP,URL等及其解释
C# 正则表达式判断IP,URL等及其解释 判断IP格式方法: public static bool ValidateIPAddress(string ipAddress) { Regex valid ...
- 使用AutoMapper 处理DTO数据对象的转换
using AutoMapper;using System; namespace DTOtEST{ class Program { static void Main(string[] args) { ...
- 【python】抄写爬淘宝已买到的宝贝的代码
教程地址:http://cuiqingcai.com/1076.html 这一篇掌握的不好.虽然代码可以跑,但是里面的很多东西都一知半解.需要有空的时候系统整理. 原代码中的正则表达式已经失效了,我自 ...
- mysql数据库设计之三范式
第一范式: 第二范式: 正解: 第三范式: 示例: 正解: BC范式: 示例: 正解:
- 更换介质:请把标有…… DVD 的盘片插入驱动器“/media/cdrom/”再按回车键“ 解决方法
https://blog.csdn.net/no7oor/article/details/12776815
- 浅谈C#多线程与UI响应
www.educity.cn 发布者:shenywww 来源:网络转载 发布日期:2014年10月06日 ...
- configure.ac中AC_CHECK_LIB的问题
编译Linux程序时,使用configure.ac生成的configure程序,时常会出现AC_CHECK_LIB检查某个库失败 而相应库通常是存在的,只是依赖于其他的库,此时,需要乃至AC_CHEC ...
- 二维字符数组利用gets()函数输入
举例: ][]; ;i<;i++) gets(a[i]); a是二维字符数组的数组名,相当于一维数组的指针, 所以a[i]就相当于指向第i个数组的指针,类型就相当于char *,相当于字符串.