Ignatius and the Princess II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6701    Accepted Submission(s):
3964

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
 
求第m个全排列。
用了个next_permutation(a,a+n)库函数。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std; int a[];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<n;i++)
a[i]=i+;
m--;
while(m--)
{
next_permutation(a,a+n);
}
for(int i=;i<n;i++)
{
if(i!=n-)
printf("%d ",a[i]);
else
printf("%d\n",a[i]);
}
}
return ;
}

HDU_1027_Ignatius and the Princess II_全排列的更多相关文章

  1. ignitius and princess 2(全排列)

    A - Ignatius and the Princess II Now our hero finds the door to the BEelzebub feng5166. He opens the ...

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

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

  3. poj 1027 Ignatius and the Princess II全排列

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

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

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

  5. 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(求第m个全排列)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/10 ...

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

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

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

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

随机推荐

  1. js 最简单的实现复制到剪切板 xl_copy

    使用 npm install xl_copy // 项目中安装 import clipboard form 'xl_copy' // 引用 element.onclick = ()=>{     ...

  2. ojdbc.jar

    Oracle的jdbc驱动是ojdbc.jar 文件,那么mysql的jdbc驱动是什么呢? 匿名 | 浏览 689 次 发布于2015-06-07 02:06   最佳答案   MySQL的JDBC ...

  3. lua中的metatable和metamethod

    --元表和元方法给lua里的值设定一些操作,让我们可以对这些操作自定义 --创建一个新的table变量时,它是不存在元表的 --在Lua中,只能设置table的元表,其他类型的值的元表,只能通过C代码 ...

  4. 问答:怎样规划CSS 中 的命名方式 怎样看待 CSS 中 BEM 的命名方式?

    好多盆友 非常纠结 css命名规则 怎么弄,还没起步就被绊住了.那么今天蝈蝈就针对这个问题来讨论一下 没什么技术 含量.但却对效率开发至关重要的 "问题". 下文是一些知乎大神的个 ...

  5. windows下检測文件改变

    这个主要是应用在我前一篇博客里提到的脚本热载入功能. 主要实现的功能检測目录内文件的变化(改变.新增.删除.重命名),当发现改变的时候通知lua又一次载入脚本.基本上就是一个windows api的使 ...

  6. python多线程实现抓取网页

    Python实现抓取网页 以下的Python抓取网页的程序比較0基础.仅仅能抓取第一页的url所属的页面,仅仅要预定URL足够多.保证你抓取的网页是无限级别的哈,以下是代码: ##coding:utf ...

  7. HDU 5090 Game with Pearls(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 Problem Description Tom and Jerry are playing a ...

  8. Ubuntu12.04.3LTS安装Oracle Java 7

    今天在ubuntu 12.04 LTS 上安装Matlab时总是出错,显示拷贝jar包(cp "xx.jar")出现错误,在网上搜索了一下发现原来是没有安装java.自己打算安装o ...

  9. 使用VS2005安装和编译QT4.53源码

    学习Qt,当然是QT4好.可是装了4.86以后,网上下载的书中的例子大多无法直接用VS执行(个人不喜欢用QT Creator),即打开pro转换的时候出错(我也懒的研究为什么出错了).看了一下发布时间 ...

  10. B1277 [HNOI2002]Tinux系统 树形dp

    这个题bzoj上没有图,luogu上样例有问题...其实这个题代码不难,但是思考起来还是有一定难度的,其实这些题的重点都在于思考.我就不写了,洛谷上唯一的题解写的挺好,大家可以看一看. 题干: 在do ...