Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int testCases = 50;
- const int maxn = 100000 + 100;
- ofstream fout;
- int n;
- int num[maxn];
- string numToStr(int x) {
- string str;
- while (x != 0) {
- str = char('0' + x % 10) + str;
- x /= 10;
- }
- return str;
- }
- string getFileInName(int index) {
- return "data/" + numToStr(index) + ".in";
- }
- string getFileOutName(int index) {
- return "data/" + numToStr(index) + ".out";
- }
- LL getRand(LL l, LL r) {
- LL rnd = rand();
- rnd = (rnd << 15) | rand();
- rnd = (rnd << 15) | rand();
- rnd = (rnd << 15) | rand();
- return rnd % (r - l + 1) + l;
- }
- void output(int fileIdx) {
- string fileInName = getFileInName(fileIdx);
- fout.open(fileInName);
- fout << n << endl;
- for (int i = 1; i <= n; ++i) {
- if (i != 1) {
- fout << " ";
- }
- fout << num[i];
- }
- fout << endl;
- fout.close();
- string fileOutName = getFileOutName(fileIdx);
- system(("std.exe < " + fileInName + " > " + fileOutName).c_str());
- }
- void writeToFile(int from, int to, int nl, int nr, int al, int ar, int onel, int oner, bool needImpossible) {
- for (int i = from; i <= to; ++i) {
- n = getRand(nl, nr);
- int tmpOnel = onel;
- int tmpOner = oner;
- if (needImpossible && getRand(0, 1) == 0) {
- tmpOnel = tmpOner = 0;
- }
- int one = getRand(tmpOnel, tmpOner);
- for (int j = 1; j <= n; ++j) {
- num[j] = getRand(al, ar);
- if (j <= one) {
- num[j] = num[j] / 3 * 3 + 1;
- } else {
- if (getRand(0, 1) == 0) {
- num[j] = num[j] / 3 * 3;
- } else {
- num[j] = num[j] / 3 * 3 + 2;
- }
- }
- }
- random_shuffle(num + 1, num + 1 + n);
- output(i);
- }
- }
- int main() {
- ios::sync_with_stdio(false);
- srand(time(0));
- // data in 20%, 1 <= n <= 100
- int one = testCases * 20 / 100;
- writeToFile(1, one, 90, 100, 90000, 95000, 900, 950, true);
- // data in 70%, 1 <= n <= 10000
- int two = testCases * 70 / 100;
- writeToFile(one + 1, two, 9000, 10000, 90000, 950000, 9000, 9500, false);
- // data in 100%, 1 <= n <= 1e5
- writeToFile(two + 1, testCases, 90000, 100000, 9000000, 9500000, 50000, 55000, false);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment