Advertisement
Saleh127

CC c2020and

Oct 3rd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. test
  12. {
  13. ll a,c,d,e,f,i,j,k,l=0,x;
  14. cin>>a;
  15. for(i=1; i<=32; i++)
  16. {
  17. j=pow(2,i);
  18. if(j==a)
  19. {
  20. l=1;
  21. break;
  22. }
  23. else if(j>a)
  24. {
  25. x=i-1;
  26. break;
  27. }
  28. }
  29. if(l)
  30. {
  31. cout<<-1<<endl;
  32. }
  33. else if(a==1) cout<<1<<endl;
  34. else if(a==3) cout<<"1 3 2"<<endl;
  35. else if(a==5) cout<<"2 3 1 5 4"<<endl;
  36. else if(a==6) cout<<"2 3 1 5 4 6"<<endl;
  37. else
  38. {
  39. vector<ll>z;
  40. for(i=a;i>=7;i--)
  41. {
  42. z.push_back(i);
  43. }
  44. for(i=0;i<z.size();i++)
  45. {
  46. if(z[i]==pow(2,x))
  47. {
  48. swap(z[i],z[i-1]);
  49. x--;
  50. }
  51. }
  52. z.push_back(4);
  53. z.push_back(5);
  54. z.push_back(6);
  55. z.push_back(2);
  56. z.push_back(3);
  57. z.push_back(1);
  58. for(i=0;i<z.size();i++)
  59. {
  60. cout<<z[i]<<" ";
  61. }
  62. cout<<endl;
  63. }
  64.  
  65. }
  66. return 0;
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement