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的,很 ...
随机推荐
- 使用gcc编译c语言解码ascii码
vi test.c 输入代码: #include<stdio.h> int main(void) { char *p = (char *)"\xE6\x8A\xB1\xE6\xA ...
- 解决EFCore缓存机制导致的数据查询错误问题
如题,在对同一个Context连续进行相同条件的查询时,会触发EFCore的缓存机制,如果这个过程中数据发生了变化,则会出现错误. 例如:有两个Context实例,一个负责查询,一个负责增删改, A_ ...
- 3D_solarSys
计算机图形学_3DsolarSys 一.软件功能 1.实现3D太阳系,有太阳.土星.土星环.地球.月球.天王星.海王星.火星.其中土星.地球.天王星.海王星.火星绕着太阳转,土星环绕着土 ...
- 嵌入式编程中使用 do{...} while(0) 的解释
最近在看esp32的idf,有一些宏定义使用了do while(0)这种看起来好像没啥用的代码.然后我查了一下资料,发现在linux内核代码中经常用到这个东西! 现在就将这个东西整理一下. 为什么在内 ...
- SystemProperities
SystemProperties与Settings.System 1 使用 SystemProperties.get 如果属性名称以“ro.”开头,那么这个属性被视为只读属性.一旦设置,属性值不能改变 ...
- 137、Java内部类之把内部类放到外部
01.代码如下: package TIANPAN; class Outer { // 外部类 private String msg = "Hello World !"; publi ...
- 吴裕雄--天生自然HADOOP操作实验学习笔记:ETL案例
实验目的 熟悉hadoop生态系统 初步了解大数据点击流分析业务 学会使用hadoop进行数据分析统计 实验原理 hadoop主要有三部分,hdfs做数据存储.mapreduce做数据计算.yarn做 ...
- A. Optimal Currency Exchange 兑换硬币,剩下的钱最少
A. Optimal Currency Exchange time limit per test 1.5 seconds memory limit per test 512 megabytes inp ...
- scrollBy 与 scrollTop的区别
scrollTo是相对于初始位置 scrollBy是相对于上次移动的最后位置
- Codeforces 598D:Igor In the Museum
D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...