Ignatius and the Princess II

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 51 Accepted Submission(s): 42
 
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
 
 
 
/*
题意:输出数列1,2...n这个数列的第m个全排列的数列 初步思路:没什么思路,全排列函数试试
*/
#include<bits/stdc++.h>
using namespace std;
int n,m;
int num[];
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF){
memset(num,,sizeof num);
for(int i=;i<n;i++){
num[i]=i+;
}
int k=;
do
{
if(k++==m-) break;
}while(next_permutation(num,num+n));
for(int i=;i<n;i++){
printf(i?" %d":"%d",num[i]);
}
printf("\n");
}
return ;
}

最新文章

  1. nginx下配置404错误页面
  2. IOS开发--仿制网易新闻
  3. EventBus框架在Android多Pane(Fragment)中的应用
  4. mongoDB文件太大查错纪录
  5. z-index的最大值、最小值
  6. 【转】Android 常用 adb 命令总结
  7. Go语言及Web框架Beego环境无脑搭建
  8. NSConditionLock
  9. BOM之history对象(转)
  10. flask +gevent+nginx+Gunicorn+supervisor部署flask应用
  11. 一键安装gitlab7在rehl6.4上
  12. apache 负载测试工具 ab
  13. 利用shell脚本或者php移动某个文件夹下的文件到各自的日期组成的目录下
  14. LeetCode之Add Two Numbers
  15. (华中科大)江南雨烟 C++ STL 专栏
  16. 使用Maven+ssm框架搭建一个web项目
  17. AngularJS 启动执行过程
  18. delphi char数组、string和Pchar的相互转换
  19. K8S 使用NFS 创建PV和PVC的例子 学习From https://blog.csdn.net/xts_huangxin/article/details/51494472
  20. APICloud APP前端框架——手机APP开发、APP制作、APP定制平台

热门文章

  1. spring 面向切面(AOP)
  2. 使用百度ueditor的插件使得代码高亮显示
  3. Count(*), Count(1) 和Count(字段)的区别
  4. python之路第五篇之装饰器:(进阶篇)
  5. CentOS7 + Nginx1.13.5 + PHP7.1.10 + MySQL5.7.19 源码编译安装
  6. PS 软件操作应用处理——粒子化任务效果
  7. swoole 入门
  8. Python实战之用类的静态方法实现登录验证
  9. webservice接口国内手机号码归属地查询
  10. Nunit测试工具使用实例