HDU 1027 Ignatius and the Princess II(逆康托展开)
来源:互联网 发布:神奇的印度人 知乎 编辑:程序博客网 时间:2024/06/03 17:28
题意:给你一个n,让你求n的全排列中第m小的序列。(n, m <= 1e5)
思路:逆康托展开 (知识见:点击打开链接)
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;const int maxn = 10;int fac[maxn] = {1, 1};bool vis[100005];void init(){ for(int i = 2 ; i < maxn; i++) fac[i] = fac[i-1]*i;}int main(void){ init(); int n, m; while(cin >> n >> m) { memset(vis, 0, sizeof(vis)); m--; int temp = 1; while(temp < n) { if((n-temp) <= 8) { int k = m/fac[n-temp]; m = m%fac[n-temp]; int cnt = 0; for(int i = 1; i <= n; i++) { if(!vis[i]) cnt++; if((cnt-1) == k) { printf("%d ", i); vis[i] = 1; break; } } } else { for(int i = 1; i <= n; i++) { if(!vis[i]) { vis[i] = 1; printf("%d ", i); break; } } } ++temp; } for(int i=1; i<=n; i++) if(!vis[i]) printf("%d\n", i); } return 0;}
阅读全文
1 0
- HDU 1027 Ignatius and the Princess II(逆康托展开)
- HDU 1027 Ignatius and the Princess II [康托逆展开]【数学】
- hdoj 1027 Ignatius and the Princess II 【逆康托展开】
- hdu 1027 ignatius and the princess ii
- HDU 1027 Ignatius and the Princess II
- HDU 1027 ( Ignatius and the Princess II )
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- Ignatius and the Princess II hdu 1027
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- 动态稀疏矩阵对应的三元组的输出,以及逆置和赋值算法
- VS 安装助手,弹出“The security key for this program currently stored on your system does not appear to be ”
- 如何对迭代器做切片操作
- 机器视觉缺陷检测-边学边做-相机选取
- 展开一个嵌套的列表
- HDU 1027 Ignatius and the Princess II(逆康托展开)
- 迭代器模式--没错就是Iterator
- hdu2845
- PAT-二叉搜索树
- 杭电acm2524矩形A + B(水题)
- FreeMaker教程(一)-----FreeMaker简介
- 如何在一个for语句中迭代多个可迭代对象
- 数组(2)
- Linux 查询网络状态和设置wlan相关