链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1027

Ignatius and the Princess II

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

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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue> using namespace std; #define N 1100 int main()
{
int n, m; while(scanf("%d%d", &n, &m)!=EOF)
{
int a[N]; for(int i=; i<=n; i++)
a[i] = i; m--; while(m--)
{
next_permutation(a+, a+n+); /// next_permutation(数组名+起始位置,数组名+长度)
} for(int i=; i<=n; i++)
printf("%d%c", a[i], i==n?'\n':' '); }
return ;
}

(全排列)Ignatius and the Princess II -- HDU -- 1027的更多相关文章

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

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

  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. poj 1027 Ignatius and the Princess II全排列

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

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

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

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

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

  8. hdoj 1027 Ignatius and the Princess II 【逆康托展开】

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

  9. hdu Ignatius and the Princess II

    Ignatius and the Princess II Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Ja ...

随机推荐

  1. unity里面查找所有物体

    测试的时候发现一个很诡异的bug,在prefab里面的物体的属性居然不断的在变化,最后一步步调试才发现,区别是查找物体的api,特此记录下 两种api Canvas[] canvasArray = ( ...

  2. cocos2dx继承结构图

    包含关系 CCDirector->CCScene->CCLayer->CCSprite->CCAction 继承关系 CCObject---CCAction(动作,控制图层运动 ...

  3. log4net 极简配置

    log4net的配置详解 分类: C#2013-10-01 22:45 5335人阅读 评论(4) 收藏 举报 log4net日志框架         前言:没买到1号回家的票,所以在祖国64岁生日之 ...

  4. USACO 2016 US Open Contest, Gold解题报告

    1.Splitting the Field http://usaco.org/index.php?page=viewproblem2&cpid=645 给二维坐标系中的n个点,求ans=用一个 ...

  5. win7 安装 node-sass报错

    由于国内网络问题,所以会导致下载node-sass二进制包失败 只需要在 ~/.npmrc(当前用户家目录下)添加下面一行: sass_binary_site=https://npm.taobao.o ...

  6. 【转】深入理解Java的接口和抽象类

    深入理解Java的接口和抽象类 对于面向对象编程来说,抽象是它的一大特征之一.在Java中,可以通过两种形式来体现OOP的抽象:接口和抽象类.这两者有太多相似的地方,又有太多不同的地方.很多人在初学的 ...

  7. postman tests实例记录(还没看,一些常用的)

    这段时间准备测试api接口,postman这个工具很是方便,特别是里面的tests的javascript脚本. 记录一下测试接口常用的tests验证的实例. 1.设置环境变量 postman.setE ...

  8. php错误:Uncaught exception com_exception with message Failed to create COM object

    本文为大家讲解的是php错误:Uncaught exception com_exception with message Failed to create COM object,感兴趣的同学参考下. ...

  9. Tornado模板转义处理

    转自:http://www.qttc.net/201305320.html tornado默认是转义所有字符,比较安全,但有时候我们的确需要把字符当做html来解析处理,因此我们需要做些处理. 示例: ...

  10. 第10课 初探 Qt 中的消息处理

    1. Qt消息模型 (1)Qt封装了具体操作系统的消息机制 (2)Qt遵循经典的GUI消息驱动事件模型 2. 信号与槽 (1)Qt中定义了与系统消息相关的概念 ①信号(Signal):由操作系统产生的 ...