Ignatius and the Princess II

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2   Accepted Submission(s) : 1
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

 
Author
Ignatius.L
 
 
 
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int str[1001];
int n,m,i;
while (scanf("%d%d",&n,&m)!=EOF)
{
for (i=0;i<n;i++)
{
str[i]=i+1;
}
for (i=1;i<m;i++) next_permutation(str,str+n);
printf("%d",str[0]);
for (i=1;i<n;i++)
{
printf(" %d",str[i]);
}
puts("");
}
return 0;
}

hdu Ignatius and the Princess II的更多相关文章

  1. HDU Ignatius and the Princess II 全排列下第K大数

    #include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include& ...

  2. (全排列)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 ...

  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. HDU 1027 Ignatius and the Princess II(康托逆展开)

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

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

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

  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. ACM-简单题之Ignatius and the Princess II——hdu1027

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

  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. hdu1027 Ignatius and the Princess II (全排列 &amp; STL中的神器)

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

随机推荐

  1. MyBatis对象关联关系----多对多的保存与查询

    模拟情景: 对象:学生,课程 关系:一个学生可选多个课程,一门课程可被多个学生选择 一.保存 1.创建数据库表,student,course,student_course,其中student_cour ...

  2. jquery教程-Jquery 获取标签个数 size()函数用法

    jquery教程-Jquery 获取标签个数 size()函数用法,size() 方法返回被 jQuery 选择器匹配的元素的数量. 语法 $(selector).size()     jQuery ...

  3. jaspersoft中分组打印

    一:前言 使用IReport已经四个月了,最近在做一个保镖,是要按照类型分类,并且这些类型要横着打印,最后还要算这个类型金额的总值,这张报表现是说需要用到子报表,最后和一个同事一起用group来分组做 ...

  4. Python基础(4)_集合、布尔类型

    一.集合 集合的作用一:关系运算集合的作用二:去重 定义集合:集合内的元素必须是唯一的:集合内的元素必须是可hash的,也是就不可变类型:集合是无序的 s={'egon',123,'egon','1' ...

  5. CentOS 7 主机加固手册-下

      CentOS 7 主机加固手册-上 CentOS 7 主机加固手册-中 CentOS 7 主机加固手册-下 0x1f 删除禁用非必要的服务 删除非必要的服务 # Remove yum remove ...

  6. C++格式输出控制

    #include<iostream> #include<string> #include<vector> #include<set> #include& ...

  7. aiohttp/asyncio 小例子和解释

    #!/usr/bin/env python # encoding: utf-8 import aiohttp import asyncio import time # 通过async def定义的函数 ...

  8. 《JAVA8实战》读书笔记之传递方法和传递lambda

    传递方法: 假设 你有一个Apple类,它 有一个getColor方法,还有一个变量inventory保存着一个Apples的列表.你可能想要选出所 有的绿苹果,并返回一个列表.通常我们用筛选(fil ...

  9. python VENV 环境 requirements.txt的生成、使用

    python项目 requirements.txt 文件,记录所有依赖包及其精确的版本号.用于新环境部署. 在虚拟环境中pip生成命令(正常环境类似): (venv) $ pip freeze > ...

  10. 利用navigator对象判断设备类型

    function getTerminalType() { //获取navigator对象 var o = navigator.userAgent, t = ""; if (/\bi ...