IMohammedNasr

Untitled

Sep 5th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define accuracy chrono::steady_clock::now().time_since_epoch().count()
  6. #define Num_of_Digits(n) ((int)log10(n) + 1)
  7.  
  8. const int N = 1e6 + 4;
  9.  
  10. int32_t permutation[N];
  11.  
  12. mt19937 rng(accuracy);
  13.  
  14. const ll INF = 1LL << 31;
  15.  
  16. using pii = pair<ll, ll>;
  17.  
  18. namespace generator
  19. {
  20.  
  21.     ll gen_int(ll l = -INF, ll r = INF)
  22.     {
  23.         uniform_int_distribution<ll> ludo(l, r);
  24.         return ludo(rng);
  25.     }
  26.  
  27.     string gen_string(int len = 0, bool upperCase = false, ll l = 1, ll r = 26)
  28.     {
  29.         // assert(len >= 0 && len <= 5e6);
  30.         // string str(len, (upperCase ? 'A' : 'a'));
  31.         string str(len, (upperCase ? 'A' : 'a'));
  32.         for (char &ch : str)
  33.         {
  34.             ch += gen_int(l, r) - 1;
  35.         }
  36.         return str;
  37.     }
  38.  
  39.     string gen_palindrome(int len = 0, bool upperCase = false, ll l = 1, ll r = 26)
  40.     {
  41.         assert(len >= 0 && len <= 5e6);
  42.         string str(len, (upperCase ? 'A' : 'a'));
  43.         for (int left = 0, right = len - 1; left <= right; left++, right--)
  44.             str[left] = str[right] = str[left] + gen_int(l, r) - 1;
  45.         return str;
  46.     }
  47.  
  48.     vector<ll> gen_array(int len = 0, ll minRange = -INF, ll maxRange = INF, bool Increasing = false, bool Decreasing = false)
  49.     {
  50.         assert(len >= 0 and len <= 5e6);
  51.         vector<ll> vec(len);
  52.         ll Delta = maxRange / len;
  53.         for (auto &x : vec)
  54.             x = gen_int(minRange, maxRange);
  55.         if (Increasing)
  56.         {
  57.             for (int i = 0; i < len; i++)
  58.                 vec[i] = (i == 0 ? 0 : vec[i - 1]) + gen_int(0, Delta);
  59.         }
  60.         if (Decreasing)
  61.         {
  62.             for (int i = len - 1; i >= 0; i--)
  63.                 vec[i] = (i == len - 1 ? 0 : vec[i + 1]) + gen_int(0, Delta);
  64.         }
  65.         return vec;
  66.     }
  67.  
  68.     vector<ll> gen_permutation(int len = 0, ll minRange = -INF, ll maxRange = INF)
  69.     {
  70.         assert(len >= 0 && len <= 5e6);
  71.         vector<ll> vec(len);
  72.         iota(vec.begin(), vec.end(), 1);
  73.         shuffle(vec.begin(), vec.end(), rng);
  74.         return vec;
  75.     }
  76.  
  77.     string gen_big_int(int len = 0, int l = 1, int r = 10)
  78.     {
  79.         assert(len >= 0 && len <= 5e6);
  80.         string str(len, '0');
  81.         for (char &ch : str)
  82.             ch += gen_int(l, r) - 1;
  83.         if (str.front() == '0')
  84.             str.front() += gen_int(l + 1, r) - 1;
  85.         return str;
  86.     }
  87.  
  88.     vector<pii> gen_tree(ll n = 0)
  89.     {
  90.         assert(n >= 0);
  91.         vector<pii> res(n ? n - 1 : 0);
  92.         // if you like to have bamboo like tree or star like tree uncomment below 8 lines
  93.         /*if (rng() % 5 == 0) { // bamboo like tree
  94.             for (int i = 1; i < n; ++i) res[i-1] = {i, i + 1};
  95.             return res;
  96.         }
  97.         if (rng() % 7 == 0) { // star tree
  98.             for (int i = 2; i <= n; ++i) res[i-2] = {1, i};
  99.             return res;
  100.         }*/
  101.         iota(permutation, permutation + 1 + n, 0);
  102.         shuffle(permutation + 1, permutation + 1 + n, rng);
  103.         for (int i = 2; i <= n; ++i)
  104.         {
  105.             ll u = i, v = gen_int(1, i - 1);
  106.             u = permutation[u], v = permutation[v];
  107.             res[i - 2] = minmax(u, v); // u < v, just for convenience while debugging
  108.         }
  109.         shuffle(res.begin(), res.end(), rng);
  110.         return res;
  111.     }
  112.  
  113.     vector<pii> simple_graph(ll n = 0, ll m = 0)
  114.     {
  115.         assert(n > 0 && m >= n);
  116.         ll max_edges = n * (n - 1) / 2;
  117.         assert(m <= max_edges);
  118.         vector<pii> res = gen_tree(n);
  119.         set<pii> edge(res.begin(), res.end());
  120.         for (int i = n; i <= m; ++i)
  121.         {
  122.             while (true)
  123.             {
  124.                 ll u = gen_int(1, n), v = gen_int(1, n);
  125.                 if (u == v)
  126.                     continue;
  127.                 auto it = edge.insert(minmax(u, v));
  128.                 if (it.second)
  129.                     break;
  130.             }
  131.         }
  132.         res.assign(edge.begin(), edge.end());
  133.         return res;
  134.     }
  135.  
  136. }
  137.  
  138. using namespace generator;
  139.  
  140. template <typename T = int>
  141. ostream &operator<<(ostream &other, const vector<T> &v)
  142. {
  143.     for (const T &x : v)
  144.         other << x << ' ';
  145.     return other;
  146. }
  147.  
  148. ostream &operator<<(ostream &other, const vector<pair<int, int>> &v)
  149. {
  150.     for (const auto &x : v)
  151.         other << x.first << ' ' << x.second << '\n';
  152.     return other;
  153. }
  154.  
  155. // comment the just below line if test cases required
  156. #define SINGLE_TEST
  157. int tests = 15;
  158.  
  159. // number of files
  160. int files = 101;
  161.  
  162. string s = "1";
  163. // complete this function according to the requirements
  164. void Generate_test()
  165. {
  166.     cout<<s<<endl;
  167.     s += "0";
  168. }
  169.  
  170. // make name of text file
  171. string made_txt(int t)
  172. {
  173.     string testcase = "Tests/test";
  174.     testcase += to_string(t);
  175.     testcase += ".txt";
  176.     return testcase;
  177. }
  178.  
  179.  
  180. // Generate File
  181. void Generate_File()
  182. {
  183.     int T = 1;
  184. #ifndef SINGLE_TEST
  185.     T = gen_int(1, tests), cout << T << '\n';
  186. #endif
  187.     while(T--){
  188.         Generate_test();
  189.     }
  190. }
  191.  
  192. int main()
  193. {
  194.     srand(accuracy);
  195.     for (int f = 1; f <= files; f++)
  196.     {
  197.         freopen(made_txt(f).c_str(), "w", stdout);
  198.         Generate_File();
  199.     }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment