-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.cpp
More file actions
80 lines (63 loc) · 1.34 KB
/
random.cpp
File metadata and controls
80 lines (63 loc) · 1.34 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
/*
* Generate random test cases
*
* */
#include <bits/stdc++.h>
using namespace std;
random_device rd;
mt19937 g(rd());
int rnum(int a,int b){
if(a>b) swap(a,b);
return a + rand()%(b-a+1);
}
vector<int> rperm(int n){
vector<int> v(n);
for (int i=0;i<n;++i) v[i]=i+1;
shuffle(v.begin(), v.end(), g);
return v;
}
vector<int> rvec(int n,int a,int b){
vector<int> v(n);
for (int i=0;i<n;++i) v[i]=rnum(a,b);
return v;
}
vector<int> rquery(int a,int b){
int t=rnum(1,2);
int x=rnum(a,b);
int y=rnum(a,b);
//if (x>y) swap(x,y);
return {t,x,y};
}
string rstring(int nchar){
vector<char> v;
for (int i=0;i<nchar;++i){
v.push_back((char)rnum(97,122));
}
return string(v.begin(),v.end());
}
int main(int argc, char* argv[]) {
srand(atoi(argv[1]));
//tc test cases
int tc=1;
cout<<tc<<'\n';
//random number
int n = rnum(1,100);
cout<<n<<'\n';
//random permutation
vector<int> p = rperm(n);
for (auto u:p) cout<<u<<' ';
cout<<'\n';
//random vector
vector<int> v = rvec(n,1,1e3);
for (auto u:v) cout<<u<<' ';
cout<<'\n';
//m random queries, t x y
int m = rnum(1,10);
cout<<m<<'\n';
while(m--){
vector<int> q = rquery(1,1e2);
for (auto u:q) cout<<u<<' ';
cout<<'\n';
}
return 0;
}