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. c# vs2008报表

    1. 做报表没做几次,第一次做的都忘记了,还好今天做一下就把报表弄成功了.报表中“参数字段”是可以变的,就是说需要自己赋值或者是要计算的.而在苏据库字段里面的是固定的值.不需要计算(注:有的字段查询出 ...

  2. 【poj3415-长度不小于k的公共子串个数】后缀数组+单调栈

    这题曾经用sam打过,现在学sa再来做一遍. 基本思路:计算A所有的后缀和B所有后缀之间的最长公共前缀. 分组之后,假设现在是做B的后缀.前面的串能和当前的B后缀产生的公共前缀必定是从前往后单调递增的 ...

  3. bzoj 1878 SDOI2009树状数组 离线操作

    本来想写2120的,结果想起来了这个 我们先对于询问左端点排序,用树状数组存区间字母个数,对于每种字母, 第一次出现的位置记录为1,剩下的记录为0,然后记录下,每种颜色 后面第一个和他相同颜色的位置 ...

  4. 安装l Xposed Framework

    How to install Xposed Framework on Android 4.x.x :   1. For Android 4.0.3 through 4.4.4 Visit this X ...

  5. mongoDB文档操作【增删改】

    MongoDB 插入文档 文档的数据结构和JSON基本一样. 所有存储在集合中的数据都是BSON格式. BSON是一种类json的一种二进制形式的存储格式,简称Binary JSON. 插入文档 Mo ...

  6. WIN8.1优化

    用WIN8.1至今,总结的所有优化的办法! 从Win7.Win8.1开始,微软为我们带来完善的系统服务.任务计划程序,这些都一定程度提升了日常使用,实现了“半自动化.半智能化”交互体验.但是对于高级用 ...

  7. 破解wifi时遇到rtl8187 - [phy1]SIOCSIFFLAGS: Name not unique on network

    当我使用我的ubuntu利用aircrack-ng套件进行wifi破解时 遇到如下问题 rtl8187 - [phy1]SIOCSIFFLAGS: Name not unique on network ...

  8. bayer转dng实现过程记录

    前言 项目中需要将imx185出来的raw数据转成dng格式,一开始认为很简单的事情,后面才发现还是挺复杂的!!!首先考虑的是不写任何代码,直接用adobe提供的转换工具来转,结果发现,不仅是adob ...

  9. 【bzoj4810】由乃的玉米田

    lxl丧心病狂-- 首先允许离线的区间询问一看就是莫队.那么我们看下怎么莫队? 不会. "由乃题多半是不可做的."于是我看了下题解--好吧果然是bitset 用bitset维护当前 ...

  10. mysql内连接、左连接、右连接举例说明

    如下: CREATE TABLE tb ( id INT PRIMARY KEY, NAME VARCHAR (20) ) ; CREATE TABLE ta ( id INT PRIMARY KEY ...