Ignatius and the Princess II
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......" |
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 |
Sample Output
1 2 3 5 6 4 |
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 ;
}
Ignatius and the Princess II的更多相关文章
- HDU 1027 Ignatius and the Princess II(康托逆展开)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- ACM-简单题之Ignatius and the Princess II——hdu1027
转载请注明出处:http://blog.csdn.net/lttree Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Othe ...
- Ignatius and the Princess II(全排列)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- HDU1027 Ignatius and the Princess II 【next_permutation】【DFS】
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- ACM-简单的主题Ignatius and the Princess II——hdu1027
转载请注明出处:http://blog.csdn.net/lttree Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Othe ...
- (next_permutation)Ignatius and the Princess II hdu102
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- HDU - 1027 Ignatius and the Princess II 全排列
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- hdu1027 Ignatius and the Princess II (全排列 & STL中的神器)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1027 Ignatiu ...
- hdoj 1027 Ignatius and the Princess II 【逆康托展开】
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
随机推荐
- 【个人笔记】《知了堂》mysql表连接
为什么使用表连接 什么是表连接? 如果数据来自多个表,那么可以采用链接查询的方式来实现.因此表连接就是多个表连接合在一起实现查询效果 表连接的原理 表连接采用的是笛卡尔乘积,称之为横向连接. 笛卡尔乘 ...
- PHP 生成毫秒时间戳
PHP的time()函数生成当前时间的秒数,但是在一些情况下我们需要获取当前服务器时间和GMT(格林威治时间)1970年1月0时0分0秒的毫秒数,与Java中的currentTimeMilis()函数 ...
- http://codeforces.com/problemset/problem/594/A
A. Warrior and Archer time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 在Ubuntu上安装Docker
原文链接:https://docs.docker.com/engine/installation/linux/ubuntu/ 这里记录的是社区版安装方式,由于平时只做开发使用所以不需要安装企业版, ...
- 基于nodejs+webSocket的聊天室(实现:加入聊天室、退出聊天室、在线人数、在线列表、发送信息、接收信息)
1 安装 socket.io模块 npm install "socket.io": "latest" 2 app.js相关 ws = require('soc ...
- 用$.getJSON() 和$.post()获取第三方数据做页面 ——惠品折页面(1)
用$.getJSON() 和$.post()获取第三方数据做页面 首页 index.html 页面 需要jquery 和 template-web js文件 可以直接在官网下载 中间导航条的固 ...
- Vue实现勾选后向数组都添加
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 强大的grep,sed和awk--用案例来讲解
准备工作: 先简单了解grep,sed和awk功能 1) grep 显示匹配特定模式的内容 grep -v 'boy' test.txt 过滤掉test.txt文件的boy,显示其余内容 grep ' ...
- C#常用的字符串处理方法
1.Replace(替换字符):public string Replace(char oldChar,char newChar);在对象中寻找oldChar,如果寻找到,就用newChar将oldCh ...
- SQL Server数据转MySql
正好用到SQL Server数据转MySql的知识,就分享一下, 准备:需要用到 Navicat Premium 百度上下载就好 1.打开连接MySQL数据库,新建数据库,双击数据库点击导入 2.导 ...