hdoj-1027-Ignatius and the Princess II(逆康拓展开)
/*
Name:
Copyright:
Author:
Date: 2018/5/2 11:07:16
Description:输出第m小的序列
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int fac[] = {,,,,,,,,};//阶乘
//康托展开的逆运算,{1...n}的全排列,中的第k个数为s[]
void reverse_kangtuo(int n,int k,int s[])
{
int i, j, t, vst[]={};
--k;
for (i=; i<n; i++)
{
if (n-i- > ) {
t = k/fac[];
} else {
t = k/fac[n-i-];
}
for (j=; j<=n; j++)
if (!vst[j])
{
if (t == ) break;
--t;
}
s[i] = j;
vst[j] = ;
if (n-i- > ) {
k %= fac[];
} else {
k %= fac[n-i-];
}
}
} int main()
{
int s[] ;
int m, n;
while (cin>>m>>n) {
memset(s, , sizeof(s)) ;
reverse_kangtuo(m, n, s);
cout<<s[];
for (int i=; i<m; i++) {
cout<<" "<<s[i];
}
cout<<endl;
}
return ;
}
hdoj-1027-Ignatius and the Princess II(逆康拓展开)的更多相关文章
- hdoj 1027 Ignatius and the Princess II 【逆康托展开】
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- HDU 1027 Ignatius and the Princess II(求第m个全排列)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/10 ...
- HDU 1027 Ignatius and the Princess II(康托逆展开)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- HDU - 1027 Ignatius and the Princess II 全排列
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- HDU 1027 Ignatius and the Princess II[DFS/全排列函数next_permutation]
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- poj 1027 Ignatius and the Princess II全排列
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- hdu 1027 Ignatius and the Princess II(正、逆康托)
题意: 给N和M. 输出1,2,...,N的第M大全排列. 思路: 将M逆康托,求出a1,a2,...aN. 看代码. 代码: int const MAXM=10000; int fac[15]; i ...
- 【HDOJ】1027 Ignatius and the Princess II
这道题目最开始完全不懂,后来百度了一下,原来是字典序.而且还是组合数学里的东西.看字典序的算法看了半天才搞清楚,自己仔细想了想,确实也是那么回事儿.对于长度为n的数组a,算法如下:(1)从右向左扫描, ...
- HDU 1027 Ignatius and the Princess II 选择序列题解
直接选择序列的方法解本题,可是最坏时间效率是O(n*n),故此不能达到0MS. 使用删除优化,那么就能够达到0MS了. 删除优化就是当须要删除数组中的元素为第一个元素的时候,那么就直接移动数组的头指针 ...
随机推荐
- mybatis-generator和TKmybatis的结合使用
mybatis-generator可以自动生成mapper和entity文件,mybatis-generator有三种用法:命令行.eclipse插件.maven插件.这里使用的是maven插件方式, ...
- MySQL的SQL MODE
SQL MODE:定义mysqld对约束等的响应行为: 查看当前模式: mysql> SHOW GLOBAL VARIABLES LIKE 'sql_mode'; 修改 ...
- LVM逻辑卷管理器
LVM概述 通过使用Linux的逻辑卷管理器(Logical Volume Manager, LVM),用户可以在系统运行时动态调整文件系统的大小,把数据从一块硬盘重定位到另一块硬盘,也可以提高I/O ...
- JavaWeb:JSP标准标签库
JavaWeb:JSP标准标签库 说明 什么是JSTL? JSP标准标签库(JavaServer Pages Standard Tag Library,JSTL)是一个定制的标签库的集合,用来解决像遍 ...
- Oracle表约束
约束的概述: 约束是在表中定义的用于维护数据库完整性的一些规则 (1).主键约束 不能为空也不能重复 在一个表中只能定义一个主键约束 Oracle会在主键上建立一个唯一索引,可以指定唯一索引的存储位置 ...
- HTML系列(1)简介
开始整理html的知识. (1)HTML HTML 是用来描述网页的一种语言. 1.HTML指的是超文本标记语言: HyperText Markup Language 2.HTML不是 ...
- VMWare虚拟机安装步骤
VMWare虚拟机安装 如果以前安装过VMware,则先检查是否卸载干净(注册表等) 一.首先下载VMware Workstation Pro,在这里提供一个下载链接:https://www.nocm ...
- 【HackerRank】The Love-Letter Mystery
James找到了他的朋友Harry要给女朋友的情书.James很爱恶作剧,所以他决定要胡搞一下.他把信中的每个单字都变成了回文.对任何给定的字符串,他可以减少其中任何一个字符的值,例如'd'可以变成' ...
- Hearbeat 工作原理
Hearbeat 原理 heartbeat (Linux-HA)的工作原理:heartbeat最核心的包括两个部分,心跳监测部分和资源接管部分,心跳监测可以通过网络链路和串口进行,而且支持冗 余链路, ...
- windows7 安装Apache2时出现failed to open the winNT service manager 提示
因为电脑实在太慢了,C盘的空间所剩无几,要想再安装大一点的软件的话,可能性很小.加之系统已经好久没有重装过了,于是重新安装windows7旗舰版,系统装好后,免不了一堆软件的重装和开发环境配置,首要的 ...