Ignatius and the Princess II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 9444    Accepted Submission(s): 5524

Problem Description

Now 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

The 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.

Output

For 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.

Sample Input

6 4 11 8

Sample Output

1 2 3 5 6 4 1 2 3 4 5 6 7 9 8 11 10

#include <iostream>
#include <algorithm> //此处可用stl,因为这基本是字典序排序。
using namespace std;
int main()
{
int a,b,c[];
while(cin>>a>>b)
{
for(int i=;i<=a;i++)
c[i]=i;
b--; //第四个排列,只需要进行3次排序就可。
while(b--)
next_permutation(c+,c++a);
for(int i=;i<a;i++)
cout<<c[i]<<" ";
cout<<c[a]<<endl;
}
return ;
}

(next_permutation)Ignatius and the Princess II hdu102的更多相关文章

  1. HDU 1027 Ignatius and the Princess II(康托逆展开)

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  2. hdu1027 Ignatius and the Princess II (全排列 &amp; STL中的神器)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1027 Ignatiu ...

  3. 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 ...

  4. HDU1027 Ignatius and the Princess II 【next_permutation】【DFS】

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  5. (全排列)Ignatius and the Princess II -- HDU -- 1027

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/100 ...

  6. 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 ( ...

  7. Ignatius and the Princess II(全排列)

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  8. ACM-简单题之Ignatius and the Princess II——hdu1027

    转载请注明出处:http://blog.csdn.net/lttree Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Othe ...

  9. ACM-简单的主题Ignatius and the Princess II——hdu1027

    转载请注明出处:http://blog.csdn.net/lttree Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Othe ...

随机推荐

  1. 对我们最常用的软件QQ的看法

    QQ聊天软件是我使用的第一款聊天软件,早在我上小学6年级的时候就开始接触这款软件了,可以说是陪伴我最久的一款软件. 相对于其他的聊天软件,QQ更加的方便,使用简单,界面也好操作,所以我爱上了这款软件. ...

  2. linux内核分析第六周学习笔记

    LINUX内核分析第六周学习总结 标签(空格分隔): 20135328陈都 陈都 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.c ...

  3. 批处理-For详解

    大纲 一 前言 二 for语句的基本用法 三 for /f (delims.tokens.skip.eol.userbackq.变量延迟) 四 for /r (递归遍历) 五 for /d (遍历目录 ...

  4. GS环境里面 9999 常用密码的加密后的值

    1. Test6530 APTZ5s6vrw1dglqO/63osA== 2. aaaaaa zgnewZXGGoqcPGtNpXTSXQ== 3. cwpass 3Me34S0+zY4xEGUFtz ...

  5. 让 VAGRANT 启动并运行起来

    这是一个帮助你快速入门Vagrant的初级教程.官方文档也可以很好的帮助你入门,但是本文更针对完全零基础的初学者并且会对某些问题直接切入正题. 本文在任何方面都不会取代官方文档,而且我建议读完本文的人 ...

  6. 在保存Bitmap的时候出现“GDI出现一般性错误”

    今天开发的时候出现过一个非常奇怪的问题,在保存最终的Bitmap图片的时候,明明使用Directory.Exist(filePath)函数判断当前路径的时候,这些路径都是有用的并且都是合法的,但是就是 ...

  7. linux 为tomcat指定jdk

    Linux为Tomecat指定JDK   在搭建Jenkin+Sonar集成时,由于系统环境配置了jdk1.7,但是jenkins在安装sonar的插件时,需要jdk1.8.,所以需要在Tomcat指 ...

  8. 非关心数据库无法进行连表查询 所以我们需要在进行一对多查询时候 无法满足 因此需要在"1"的一方添加"多"的一方的的id 以便用于进行连表查询 ; 核心思想通过id进行维护与建文件

     非关心数据库无法进行连表查询 所以我们需要在进行一对多查询时候 无法满足 因此需要在"1"的一方添加"多"的一方的的id 以便用于进行连表查询 ; 核心思想通 ...

  9. Django-website 程序案例系列-17 forms表单验证的字段解释

    1.Django内置字段如下: Field required=True, 是否允许为空 widget=None, HTML插件 label=None, 用于生成Label标签或显示内容 initial ...

  10. RedIsGood TopCoder - 9915(概率dp)

    ---恢复内容开始--- 论文题: 桌面上有 R 张红牌和 B 张黑牌,随机打乱顺序后放在桌面上,开始一张一张 地翻牌,翻到红牌得到 1 美元,黑牌则付出 1 美元.可以随时停止翻牌,在最优策略下平均 ...