Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<string>
  5. #include<vector>
  6. #include<set>
  7. #include<map>
  8. #include<queue>
  9. #include<iterator>
  10. #include<algorithm>
  11. using namespace std;
  12. bool bi[1021];
  13. int ar[1021];
  14. int main(){
  15. /*freopen("i_suck.in","r",stdin);
  16. freopen("i_suck.out","w",stdout);*/
  17. long int a,b,c,d,e,x,y,z,n,k;
  18. while(scanf("%ld %ld",&n,&k)==1){
  19. for(a=0;a<=n;a++) bi[a]=0;
  20. for(a=1;a<n;a++){
  21. z=n-a;
  22. x=1;
  23. for(b=1;b<=z;b++) x=x*b;
  24. bool wi; wi=false;
  25. if(x>k){ continue; }
  26. for(b=1;b<=z+1;b++)
  27. if(x*b>=k){
  28. ar[a]=b;
  29. k=k-x*(b-1); if(k==1) k=0; break;
  30. }
  31. }
  32. bool zi;
  33. zi=false;
  34. for(a=1;a<=n;a++){
  35. if(ar[a]==0){ for(c=1;c<=n;c++) if(!bi[c]){ if(zi) cout<<" "; cout<<c; bi[c]=1; zi=true; break; } }
  36. if(ar[a]){ e=0;
  37. for(c=1;c<=n;c++){
  38. if(!bi[c]) e++;
  39. if(e>=ar[a]){ if(zi) cout<<" "; cout<<c; bi[c]=1; break; }
  40. }
  41. }
  42. }
  43. cout<<endl;
  44. }
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement