NHumme

Untitled

Apr 21st, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <vector>
  6. #include <string>
  7. #include <set>
  8. #include <stack>
  9. #include <queue>
  10. #include <deque>
  11. #include <fstream>
  12. #include <ctime>
  13. using namespace std;
  14.  
  15. #define TASK "path"
  16.  
  17.  
  18. #define ll long long
  19.  
  20. ll to_dm(string &s) {
  21.     ll k = 1;
  22.     ll ans = 0;
  23.     for (int i = s.size() - 1; i >= 0; i--) {
  24.         ans = ans + (s[i] - '0') * k;
  25.         k = k * 2;
  26.     }
  27.     return ans;
  28. }
  29.  
  30. int main() {
  31.  
  32.     srand(time(0));
  33.  
  34. #ifdef _DEBUG
  35.     //freopen("debug.in", "r", stdin);
  36.     //freopen("debug.out", "w", stdout);
  37. #else
  38.     //freopen(TASK".in", "r", stdin);
  39.     //freopen(TASK".out", "w", stdout);
  40.     //freopen("input.txt", "r", stdin);
  41.     //freopen("output.txt", "w", stdout);
  42. #endif // _DEBUG
  43.  
  44.     ios_base::sync_with_stdio(0);
  45.     cin.tie(0);
  46.     cout.tie(0);
  47.     cout.precision(6);
  48.  
  49.     ofstream fout;
  50.     for (int i = 2; i < 100; i++) {
  51.         string filename = "";
  52.         filename += (i < 10 ? '0' : char(i / 10 + '0'));
  53.         filename += char(i % 10 + '0');
  54.         fout.open(filename + ".tst");
  55.  
  56.         int n, k;
  57.         if (i >= 80) {
  58.             n = rand() % 900000000 + 100000000, k = 10;
  59.         }
  60.         else {
  61.             n = rand() % 999999999 + 1, k = rand() % 10 + 1;
  62.         }
  63.         fout << n << " " << k;
  64.  
  65.         fout.close();
  66.         fout.open(filename + ".ans");
  67.  
  68.         string s = "";
  69.         for (int i = 0; i < k; i++) {
  70.             s += '1';
  71.         }
  72.         for (int i = k; i < 30; i++) {
  73.             s += '0';
  74.         }
  75.         reverse(s.begin(), s.end());
  76.         vector<int>ans;
  77.         do {
  78.             ll k = to_dm(s);
  79.             if (k <= n)
  80.                 ans.push_back(k);
  81.             else
  82.                 break;
  83.         } while (next_permutation(s.begin(), s.end()));
  84.  
  85.         fout << ans.size() << endl;
  86.  
  87.         for (int i = 0; i < ans.size() && i < 1000; i++) {
  88.             fout << ans[i] << endl;
  89.         }
  90.  
  91.         fout.close();
  92.     }
  93.  
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment