Dmaxiya

孤独的数字三 数据生成

Dec 18th, 2025 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int testCases = 50;
  6. const int maxn = 100000 + 100;
  7. ofstream fout;
  8. int n;
  9. int num[maxn];
  10.  
  11. string numToStr(int x) {
  12.     string str;
  13.     while (x != 0) {
  14.         str = char('0' + x % 10) + str;
  15.         x /= 10;
  16.     }
  17.     return str;
  18. }
  19.  
  20. string getFileInName(int index) {
  21.     return "data/" + numToStr(index) + ".in";
  22. }
  23.  
  24. string getFileOutName(int index) {
  25.     return "data/" + numToStr(index) + ".out";
  26. }
  27.  
  28. LL getRand(LL l, LL r) {
  29.     LL rnd = rand();
  30.     rnd = (rnd << 15) | rand();
  31.     rnd = (rnd << 15) | rand();
  32.     rnd = (rnd << 15) | rand();
  33.     return rnd % (r - l + 1) + l;
  34. }
  35.  
  36. void output(int fileIdx) {
  37.     string fileInName = getFileInName(fileIdx);
  38.     fout.open(fileInName);
  39.     fout << n << endl;
  40.     for (int i = 1; i <= n; ++i) {
  41.         if (i != 1) {
  42.             fout << " ";
  43.         }
  44.         fout << num[i];
  45.     }
  46.     fout << endl;
  47.     fout.close();
  48.     string fileOutName = getFileOutName(fileIdx);
  49.     system(("std.exe < " + fileInName  + " > " + fileOutName).c_str());
  50. }
  51.  
  52. void writeToFile(int from, int to, int nl, int nr, int al, int ar, int onel, int oner, bool needImpossible) {
  53.     for (int i = from; i <= to; ++i) {
  54.         n = getRand(nl, nr);
  55.         int tmpOnel = onel;
  56.         int tmpOner = oner;
  57.         if (needImpossible && getRand(0, 1) == 0) {
  58.             tmpOnel = tmpOner = 0;
  59.         }
  60.         int one = getRand(tmpOnel, tmpOner);
  61.         for (int j = 1; j <= n; ++j) {
  62.             num[j] = getRand(al, ar);
  63.             if (j <= one) {
  64.                 num[j] = num[j] / 3 * 3 + 1;
  65.             } else {
  66.                 if (getRand(0, 1) == 0) {
  67.                     num[j] = num[j] / 3 * 3;
  68.                 } else {
  69.                     num[j] = num[j] / 3 * 3 + 2;
  70.                 }
  71.             }
  72.         }
  73.         random_shuffle(num + 1, num + 1 + n);
  74.         output(i);
  75.     }
  76. }
  77.  
  78. int main() {
  79.     ios::sync_with_stdio(false);
  80.     srand(time(0));
  81.  
  82.     // data in 20%, 1 <= n <= 100
  83.     int one = testCases * 20 / 100;
  84.     writeToFile(1, one, 90, 100, 90000, 95000, 900, 950, true);
  85.  
  86.     // data in 70%, 1 <= n <= 10000
  87.     int two = testCases * 70 / 100;
  88.     writeToFile(one + 1, two, 9000, 10000, 90000, 950000, 9000, 9500, false);
  89.  
  90.     // data in 100%, 1 <= n <= 1e5
  91.     writeToFile(two + 1, testCases, 90000, 100000, 9000000, 9500000, 50000, 55000, false);
  92.  
  93.     return 0;
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment