-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGenerator(for testing).cpp
More file actions
146 lines (137 loc) · 3.59 KB
/
Generator(for testing).cpp
File metadata and controls
146 lines (137 loc) · 3.59 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// This file is used to generate random testcase.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
const int N = 1e6 + 5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int genNum(int l, int r) {
return l + rand() % (r - l + 1);
}
vector<int> genArr(int n, int l, int r) {
vector<int> res;
for (int i = 0; i < n; i++) {
res.push_back(genNum(l, r));
}
return res;
}
vector<int> genArrNoRep(int n, int l, int r) {
vector<int> res;
map<int, int> done;
for (int i = 0; i < n; i++) {
int cur = genNum(l, r);
while (done[cur]) {
cur = genNum(l, r);
}
done[cur] = 1;
res.push_back(cur);
}
return res;
}
string genStrAlpha(int n, char ccase) {
string res = "";
for (int i = 0; i < n; i++) {
res.push_back(ccase + rand() % 26);
}
return res;
}
string genStrBinary(int n, char one, char two) {
string res = "";
for (int i = 0; i < n; i++) {
if (rand() % 2 == 0)
res.push_back(one);
else
res.push_back(two);
}
return res;
}
string genStrTernary(int n, char one, char two, char three) {
string res = "";
for (int i = 0; i < n; i++) {
if (rand() % 3 == 0)
res.push_back(one);
else if (rand() % 3 == 1)
res.push_back(two);
else
res.push_back(three);
}
return res;
}
string genStrQuad(int n, char one, char two, char three, char four) {
string res = "";
for (int i = 0; i < n; i++) {
if (rand() % 4 == 0)
res.push_back(one);
else if (rand() % 4 == 1)
res.push_back(two);
else if (rand() % 4 == 2)
res.push_back(three);
else
res.push_back(four);
}
return res;
}
void genGraph(int n, int m) {
m = min(m, (n * (n - 1)) / 2);
cout << n << ' ' << m << endl;
map<pair<int, int>, bool> done;
vector<pair<int, int>> edges;
for (int i = 0; i < m; i++) {
while (true) {
int x = genNum(1, n);
int y = genNum(1, n);
if (x == y)continue;
if (!done[ {x, y}] and !done[ {y, x}]) {
edges.push_back({x, y});
done[ {x, y}] = 1;
done[ {y, x}] = 1;
break;
}
}
}
for (auto x : edges)
cout << x.first << ' ' << x.second << endl;
return ;
}
vector<int> genPerm(int n) {
vector<int> res;
for (int i = 0; i < n; i++)
res.push_back(i + 1);
random_shuffle(res.begin(), res.end());
return res;
}
void genTree(int n) {
assert(n >= 0);
int permutation[n + 14];
vector<pair<int, int>> res(n ? n - 1 : 0);
iota(permutation, permutation + 1 + n, 0);
shuffle(permutation + 1, permutation + 1 + n, rng);
for (int i = 2; i <= n; ++i) {
int u = i, v = genNum(1, i - 1);
u = permutation[u], v = permutation[v];
res[i - 2] = minmax(u, v);
}
shuffle(res.begin(), res.end(), rng);
cout << n << endl;
for (auto x : res)
cout << x.first << ' ' << x.second << endl;
return ;
}
string genKAlphaString(int n, int k) {
string res = "";
for (int i = 0; i < n; i++)
res.push_back('a' + rand() % k);
return res;
}
int32_t main() {
srand(chrono::steady_clock::now().time_since_epoch().count());
// for testcase;
cout << 1 << endl;
int n = genNum(3, 10);
vector<int> temp = genArr(n, 1, 10);
cout << n << endl;
for (auto t : temp )
cout << t << " ";
cout << endl;
return 0;
}