1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #include <cstdio> #include <vector> #include <utility> #include <cassert> #include <cstdlib> #include <fstream> #include <iostream> #include <algorithm>
#define hb bh
using namespace std;
const int maxn = 1000000;
int n, m, seed; int bh[maxn]; vector<pair<int, int> > ve; vector<int> rt; vector<int> ln;
int main(int argc, char** argv) { assert(argc == 4); ofstream fout(argv[1]); sscanf(argv[2], "%d", &n); sscanf(argv[3], "%d", &seed); srand((unsigned) seed); fout << n << '\n'; mt19937 rnd((unsigned) seed); int lim = n / 3; for (int i = 1; i <= n; ++i) { bh[i] = i; } int Lrt = max(1, max(lim - (lim / 10), lim - 10)); random_shuffle(bh + 1, bh + n + 1); rt.push_back(bh[1]); for (int i = 2; i <= lim; ++i) { ve.push_back(make_pair(bh[i], rt[rnd() % rt.size()])); if (i - Lrt > 1) { rt.push_back(hb[i - Lrt]); } } for (int i = lim + 1; i <= n; ++i) { if (ln.empty() || !(rnd() % max(3, lim >> 3))) { ve.push_back(make_pair(hb[i], rt[rnd() % rt.size()])); } else { ve.push_back(make_pair(hb[i], ln[max(0, (int) (ln.size() - (rnd() % 100) - 1))])); } ln.push_back(hb[i]); } random_shuffle(ve.begin(), ve.end()); for (auto x : ve) { if (rnd() & 1) { fout << x.first << ' ' << x.second << '\n'; } else { fout << x.second << ' ' << x.first << '\n'; } } fout.close(); return 0; }
|