Codeforces 513B2 - Permutations (思维)
来源:互联网 发布:mysql定时执行sql语句 编辑:程序博客网 时间:2024/04/30 03:17
题意
P为一个序列。
定义
现在要求输出所有满足F(n)最大的序列中字典序第k大的序列。
思路
先求出怎样的序列能满足F(p)最大。
假设现在是一个空的序列,那么1是最小的元素,它只能被放在序列的最前面或者最后面。因为如果放在中间产生的结果必定小。
之后考虑2,也和1一样。把1填的那个位置去除之后2也只能放在剩下来的最前面或者最后面。以此类推。
所以总共合法的排列有
接下来考虑字典序。
当放1时,如果放第一个,那么剩下来的可能数是
剩下来的排列数其实就是
以此类推。把1放后面之后减去1放前面能得到的情况,然后考虑2。和考虑1是一样的。
代码
int vis[100];vector<int> ans;int main(){ LL n, k; cin >> n >> k; int pos = 1; for (int i = 0; i < n; i++) for (; pos <= n; pos++) { if (k > (1ll<<(n-pos-1))) k -= (1ll<<(n-pos-1)); else { vis[pos] = 1; ans.PB(pos); pos++; break; } } for (int i = n; i >= 1; i--) { if (vis[i]) continue; ans.PB(i); } for (auto i: ans) printf("%d ", i); return 0;}
0 0
- Codeforces 513B2 - Permutations (思维)
- Codeforces 513B2 Permutations
- Codeforces 513B2 or 513B1 Permutations 策略题
- CodeForces 513B1 Permutations
- Codeforces 513B Permutations
- Codeforces 395 B2. iwiwi
- Codeforces 316B2 EKG
- CodeForces 617B2
- codeforces 177B2 B2. Rectangular Game(数论)
- Codeforces 340E Iahub and Permutations【思维+错排Dp】
- Permutations CodeForces
- codeforces——395B2——B2. iwiwi
- CF#119 Permutations(思维)
- (513B2)codeforce
- b2
- B2
- Codeforces 124B. Permutations
- CodeForces 124B Permutations
- 中国房地产开发商排名百强榜单
- Java 命名习惯总结
- qemu虚拟机与外部网络的通信
- Freescale i.MX6 Linux Ethernet Driver驱动源码分析(一)
- 网络流最大流ISAP算法[草地排水][运输问题1]
- Codeforces 513B2 - Permutations (思维)
- Activity的Launch mode详解 singleTask正解
- java常见异常
- Freescale i.MX6 Linux Ethernet Driver驱动源码分析(二)
- 最简单的目标跟踪-模板匹配跟踪
- Redis的持久化-AOF
- EasyUI中,datagrid页码上的自定义按钮不显示问题
- [Math]简单产生白噪声的算法
- 什么时候需要用到RCC_APB2Periph_AFIO--复用IO时钟的使用