Ignatius and the Princess II
給你N個整數,分別是1,2,3,。。。N。問你全排列的第M個排列為多少?
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
AC碼:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=10010;
int a[maxn];
int main()
{
int n,m;
while(~scanf("%d %d",&n,&m))
{
memset(a,0,sizeof(a));
int t=1;
for(int i=0;i<n;i++)
a[i]=i+1;
while(next_permutation(a,a+n))
{//引數n指的是 進行排列的長度
if(t++==m-1)
break;
}
for(int i=0;i<n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-1]);
}
return 0;
}
相關文章
- Ignatius and the Princess IV——伊格納提烏斯和四公主
- HDU 母函式簡單題 - 找單詞/Ignatius and the Princess III/Square Coins/Holding Bin-Laden Captive!函式APT
- The Princess And The Pea
- Range Addition II 範圍求和 II
- Hackable: II
- (原創) 如何破解Quartus II 7.2 SP1? (IC Design) (Quartus II) (Nios II)iOS
- Reflective Journal II
- Bracket Sequences IIRacket
- Collecting Numbers II
- 劍指 Offer 14- II. 剪繩子 II
- Spiral-matrix-ii
- 設計模式II設計模式
- leetcode-90. Subsets IILeetCode
- Leetcode 40 Combination Sum IILeetCode
- 113-Path Sum II
- 119 Pascal's Triangle II
- 253. Meeting Rooms IIOOM
- *** 126. Word Ladder II
- A + B Problem II hd 1002
- 字串的調整II字串
- Leetcode 213 House Robber IILeetCode
- HDU 1002 A + B Problem II
- 137-Single Number II
- 126-Word Ladder II
- LeetCode 1103[分糖果II]LeetCode
- 『vulnhub系列』HACKABLE-II
- 59. Spiral Matrix II
- 52. N皇后 II
- 3人獨立團隊分享3D roguelite遊戲《Tower Princess》的開發歷程3D遊戲
- LeetCode—253.會議室 II(Meeting Rooms II)——分析及程式碼(C++)LeetCodeOOMC++
- [LeetCode] 210. Course Schedule IILeetCode
- [LeetCode] 305. Number of Islands IILeetCode
- [LeetCode] 212. Word Search IILeetCode
- 令人困惑的 TensorFlow!(II)
- [Leetcode]253. Meeting Rooms IILeetCodeOOM
- [LeetCode] 2105. Watering Plants IILeetCode
- LeetCode 52. N皇后 IILeetCode
- [leetcode]linked-list-cycle-iiLeetCode