1 #include <iostream> 2 #include <cstdlib> 3 #include <cstring> 4 #include <queue> 5 #include <cstdio> 6 #include <algorithm> 7 #include <map> 8 #define LL long long 9 10 using namespace std; 11 12 void unCantor(int X,int n) 13 { 14 int a[20],num[20],used[20]; 15 int fact[15]; 16 memset(used,0,sizeof(used)); 17 fact[0] = fact[1] = 1; 18 for(int i = 2; i <= 15; i++) 19 fact[i] = fact[i-1]*i; 20 21 for(int i = 1; i <= n; i++) 22 { 23 a[i] = X/fact[n-i]; 24 X %= fact[n-i]; 25 int cnt = 0; 26 for(int j = 1; j <= n; j++) 27 { 28 if(!used[j]) 29 cnt = cnt+1; 30 if(cnt == a[i] + 1) 31 { 32 num[i] = j; 33 used[j] = 1; 34 break; 35 } 36 } 37 } 38 for(int i = 1; i <= n; i++) 39 printf("%d%c",num[i],i == n?‘\n‘:‘ ‘); 40 } 41 42 void solve() 43 { 44 int n,X; 45 scanf("%d %d",&X,&n); 46 unCantor(X,n); 47 } 48 49 int main(void) 50 { 51 int t; 52 scanf("%d",&t); 53 while(t--) 54 { 55 solve(); 56 } 57 return 0; 58 }
时间: 2024-12-20 01:07:01