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了. 删除优化就是当须要删除数组中的元素为第一个元素的时候,那么就直接移动数组的头指针 ...
随机推荐
- GCE 创建一个Linux VM
sudo yum install wget 安装Java sudo wget --no-check-certificate --no-cookies --header "Cookie: or ...
- Windows.old
如果通过执行自定义安装来安装 Windows 7,而没有在安装过程中格式化分区,则以前版本的 Windows中使用的文件存储在 Windows.old文件夹中.此文件夹中文件的类型取决于您的电脑.使用 ...
- Python操作——Memcached
Memcached是一个高性能的分布式内存对象缓存系统,用于Web应用以减轻数据库的负载. 它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度. Memcached ...
- python常用模块——random模块
参考博客:http://www.360doc.com/content/14/0430/11/16044571_373443266.shtml 今天突然想起python该怎么生成随机数?查了一下,贴出实 ...
- 前端基础之JavaScript_(4)_js的作用域
js作用域 作用域就是变量与函数的可访问范围,即作用域控制着变量与函数的可见性和生命周期.在JavaScript中,变量的作用域有全局作用域和局部作用域两种. js的作用域 1. 全局作用域(Glob ...
- MYSQL:基础—主键
MYSQL:基础—主键 1.什么是主键 表中的每一行都应该具有可以唯一标识自己的一列(或一组列).而这个承担标识作用的列称为主键. 如果没有主键,数据的管理将会十分混乱.比如会存在多条一模一样的记录, ...
- 对JAVA的集合的理解
对JAVA的集合的理解是相对于数组 1.数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型) 2.JAVA集合可以存储和操作数目不固定的一组数据. 3.所有的JAVA集合都位 ...
- 安装MySQL的详细步骤
安装步骤如下: 1.打开网址:http://www.mysql.com/ ↓ 2.选择“Download”->“Windows”(此安装步骤只是在Window10 中进行,如有需要,其他系统可参 ...
- Linux安装jdk10
1.官网下载jdk10 下载方式两种,一种是wget下载,一种是windows系统下载,然后上传到linux系统上. 2.解压到/usr/local/java mkdir /usr/local/jav ...
- window7 3G/4G拨号操作
Win7系统Modem拨号操作指导:https://wenku.baidu.com/view/bb855b1dc77da26925c5b0e1.html 拨号上网设置APN,拨号号码,帐号和密码:ht ...