Advertisement
ahamed210

729 - The Hamming Distance Problem

Nov 5th, 2021
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef int l;
  4. typedef long long int ll;
  5. #define loop(a, b) for(int i = a; i < b; i++)
  6. #define PI acos(-1.0)
  7. const ll INF = LLONG_MAX;
  8.  
  9. const ll mod = 1000000007;
  10. ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b, a % b); }
  11.  ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
  12. ll power(ll a, ll b){ll res = 1;while(b){if(b&1) res = (res*a)%mod;b>>=1;a = (a*a)%mod;}return res%mod;}
  13. //leftmost set bit
  14. l clz(int N) {return N ? 32 - __builtin_clz(N) : -(1e9+1);}
  15. //ll clz(unsigned long long N){return N ? 64 - __builtin_clzll(N) : -(1e18+1);}
  16. ll setbit(ll x){return __builtin_popcountll(x);}
  17. //ll power(ll a, ll b){ll res = 1;while(b){if(b&1) res = (res*a);b>>=1;a = (a*a);}return res;}
  18. bool arraySortedOrNot(int arr[], int n){if (n == 0 || n == 1) return true;for (int i = 1; i < n; i++)if (arr[i - 1] > arr[i]) return false;return true;}
  19. // long long v[400002];
  20. // void Quicksort(int begin,int end){
  21. //   int e,b,aux,p;b=begin;e=end;p=v[(e+b)/2];
  22. //   while(v[b]<p){b++;}while(v[e]>p){e--;}while(b<e){aux=v[b];v[b]=v[e];v[e]=aux;do{b++;}while(v[b]<p);
  23. //   do{e--;}while(v[e]>p);}if(begin<e){ Quicksort(begin,e);}
  24. //   if(e+1<end){ Quicksort(e+1,end);}
  25. // }
  26.  
  27. void run(){
  28.     ios::sync_with_stdio(false);
  29.     cin.tie(NULL);
  30.     cout.tie(NULL);
  31. #ifndef ONLINE_JUDGE
  32.     freopen("input.txt", "r", stdin);
  33.     freopen("output7.txt", "w", stdout);
  34. #else
  35. #endif
  36. }
  37.  
  38. l t = 1;
  39.  
  40. void solve(){
  41.     if(t != 1) cout << endl;
  42.     l a, b;cin>>a>>b;
  43.     string s = "";
  44.     loop(0, a-b) s+=('0');
  45.     loop(a-b, a) s+=('1');
  46.     cout << s << endl;
  47.     while(next_permutation(s.begin(), s.end())){
  48.         cout << s << endl;
  49.     }
  50.     t++;
  51. }
  52.  
  53. int main()
  54. {
  55.     //clock_t tStart = clock();
  56.     ios::sync_with_stdio(false);
  57.     cin.tie(NULL);
  58.     cout.tie(NULL);
  59.     //run();
  60.     l n;cin>>n;
  61.     //dummy getline
  62.     //string s;getline(cin,s);
  63.     //char s[2100];
  64.     //while(cin>>s) {solve(s);}
  65.     while(n--){solve();}
  66.     //l n;
  67.     //while(cin>>n && n){solve(n);}
  68.     //cout << endl;
  69.     //printf("Time taken: %.10fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement