poj 1027 Ignatius and the Princess II全排列
Ignatius and the Princess II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12948 Accepted Submission(s): 7412
our hero finds the door to the BEelzebub feng5166. He opens the door
and finds feng5166 is about to kill our pretty Princess. But now the
BEelzebub has to beat our hero first. feng5166 says, "I have three
question for you, if you can work them out, I will release the Princess,
or you will be my dinner, too." Ignatius says confidently, "OK, at
last, I will save the Princess."
"Now I will show you the first
problem." feng5166 says, "Given a sequence of number 1 to N, we define
that 1,2,3...N-1,N is the smallest sequence among all the sequence which
can be composed with number 1 to N(each number can be and should be use
only once in this problem). So it's easy to see the second smallest
sequence is 1,2,3...N,N-1. Now I will give you two numbers, N and M. You
should tell me the Mth smallest sequence which is composed with number 1
to N. It's easy, isn't is? Hahahahaha......"
Can you help Ignatius to solve this problem?
input contains several test cases. Each test case consists of two
numbers, N and M(1<=N<=1000, 1<=M<=10000). You may assume
that there is always a sequence satisfied the BEelzebub's demand. The
input is terminated by the end of file.
each test case, you only have to output the sequence satisfied the
BEelzebub's demand. When output a sequence, you should print a space
between two numbers, but do not output any spaces after the last number.
11 8
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int a[];
int n,m;
int main()
{
while(cin>>n>>m)
{
int cnt=;
memset(a,,sizeof(a));
for(int i=;i<n;i++)
a[i]=i+;
do
{
cnt++;
if(cnt==m)
break;
}while(next_permutation(a,a+n));
for(int i=;i<n;i++)
{
if(i==)
cout<<a[i];
else
cout<<' '<<a[i];
}
cout<<endl;
}
return ;
}
poj 1027 Ignatius and the Princess II全排列的更多相关文章
- 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(求第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[DFS/全排列函数next_permutation]
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 ( ...
- 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 大的 n 个数全排列 DFS可过 #include <iostream> using namespace std; int n,m; ]; bool flag; ]; void d ...
- 【HDOJ】1027 Ignatius and the Princess II
这道题目最开始完全不懂,后来百度了一下,原来是字典序.而且还是组合数学里的东西.看字典序的算法看了半天才搞清楚,自己仔细想了想,确实也是那么回事儿.对于长度为n的数组a,算法如下:(1)从右向左扫描, ...
- HDU 1027 Ignatius and the Princess II 选择序列题解
直接选择序列的方法解本题,可是最坏时间效率是O(n*n),故此不能达到0MS. 使用删除优化,那么就能够达到0MS了. 删除优化就是当须要删除数组中的元素为第一个元素的时候,那么就直接移动数组的头指针 ...
- HDU 1027 Ignatius and the Princess II 排列生成
解题报告:1-n这n个数,有n!中不同的排列,将这n!个数列按照字典序排序,输出第m个数列. 第一次TLE了,没注意到题目上的n和m的范围,n的范围是小于1000的,然后m的范围是小于10000的,很 ...
随机推荐
- Python中self的用法
在Python类中规定,函数的第一个参数是实例对象本身,并且约定俗成,把其名字写为self.其作用相当于java中的this,表示当前类的对象,可以调用当前类中的属性和方法. 在python中,类是通 ...
- JS 数组相关
数组 function SelectLoadTable() { var mids = $("#mids").val(); var halls = $("#halls&qu ...
- Redis 的使用
1. 概念: redis是一款高性能的NOSQL系列的非关系型数据库 1.1.什么是NOSQL NoSQL(NoSQL = Not Only SQL),意即"不仅仅是SQL",是一 ...
- 用Navicat连接阿里云ECS服务器上的MySQL数据库,连接不上,并且报10060错误
设置远程访问(使用root密码): grant all privileges on . to 'root' @'%' identified by '123456'; flush privileges; ...
- 五、centos7安装mysql:安装mysqlser
一.下载通用安装二进制包 先下载mysql安装包:打开 http://dev.mysql.com/downloads/mysql/ 选择 linux - Generic并在其下选择 Linux - G ...
- [Linux] day07——查看及过滤文本
查看及过滤文本 =====================================cat concatenate -n 添加行号------------------- ...
- Xcode Edit Schemes
关于本文:有关“Xcode Edit Schemes”的设置,还是有很大的学问的.由于时间关系,我一点一点的补充. 1.在开发的时候,至少将Run的Build Configuration设置为Debu ...
- VMware安装CentOS操作系统详细步骤
目录 创建虚拟机(买电脑) 1. 创建新虚拟机 2. 自定义配置虚拟机 3. 选择虚拟机硬件兼容性 4. 安装虚拟机创建系统 5. 选择虚拟机操作系统 6. 设置虚拟机名字和存放位置 7. 设置虚拟机 ...
- ZCGL大数据平台性能优化
对HBase数据库建索引 参见:基于Phoenix对HBase建索引 https://www.cnblogs.com/ratels/p/11203313.html 将HBase访问微服务整合到模块 ...
- 注意重写类的equals()方法
注意在java中在比较引用类型时==和原生的equals()方法比较的都是看它们否是同一个对象(说的更直白一点就是他们在内存的位置是否是一样的),但我们在真实世界中关注的往往只是其中的某个属性是否相等 ...