1. Randomly generated data:
1. Randomly generate a number:
It's very simple. The mod here depends on the maximum number you want to generate.
int random(int mod){ return (long long)rand()*rand()%mod; } int main(){ freopen("data.in","w",stdout); srand((unsigned)time(0)); printf("%d",random()); return 0; }
2. Random generation of integer sequence:
Randomly generate N < = 10e5 integers with absolute value within 10e9
int random(int mod){ return (long long)rand()*rand()%mod; } int main(){ freopen("data.in","w",stdout); srand((unsigned)time(0)); int n=random(100000)+1; int m=1000000000; for(int i=1;i<=n;i++){ a[i]=random(2*m+1)-m; printf("%d ",a[i]); } }
3. Randomly generate interval columns:
m [1,n] subintervals are randomly generated, which can be used as operation sequences of data structure topics.
int random(int mod){ return (long long)rand()*rand()%mod; } int main(){ freopen("data.in","w",stdout); srand((unsigned)time(0));
for(int i=1;i<=m;i++){ int l=random(n)+1; int r=random(n)+1; if(l>r) swap(l,r); printf("%d %d",l,r); } }
4. Random Spanning Tree:
A tree with n points is randomly generated and output in the form of undirected graph with n points and n-1 edges. Each edge is attached with a positive integer weight within 1e9.
int random(int mod){ return (long long)rand()*rand()%mod; } int main(){ freopen("data.in","w",stdout); srand((unsigned)time(0)); for(int i=2;i<=n;i++){ int fa=random(i-1)+1; int val=rand(1000000000)+1; printf("%d %d %d\n",fa,i,val); } }
5. Randomly generated graph:
A random undirected graph with n points and m edges is generated. There are no double edges, self rings and must be connected. Ensure that 5 ≤ n ≤ m ≤ n*(n-1)/4 ≤ 1e6;
int random(int mod){ return (long long)rand()*rand()%mod; } int main(){ freopen("data.in","w",stdout); srand((unsigned)time(0)); pair<int,int> e[1000005]; map<pair<int,int>,bool> h; for(int i=1;i<n;i++){ int fa=random(i)+1; e[i]=make_pair(fa,i+1); h[e[i]]=h[make_pair(i+1,fa)]=1; } for(int i=n;i<=m;i++){ int x,y; do{ x=random(n)+1,y=random(n)+1; }while(x==y||h[make_pair(x,y)]); e[i]=make_pair(x,y); h[e[i]]=h[make_pair(y,x)]=1; } random_shuffle(e+1,e+m+1); for(int i=1;i<=m;i++){ printf("%d %d\n",e[i].first,e[i].second); } }
Then write a set of violence named bf.cpp, a set of positive solution you think is named sol.cpp, and compile it. Pay attention to write freeopen, and put it under a folder (should be right) (put it directly in C here), and then run the following program:
No matter how you want to save the run:
#include<cstdlib> #include<cstdio> #include<ctime> int main(){ for(int T=1;T<=frequency;T++) { system("C:\\random.exe"); double st=clock(); system("C:\\sol.exe"); double ed=clock(); system("C:\\bf.exe"); if(system("fc C:\\data.out C:\\data.ans")) { puts("Wrong Answer"); return 0; } else printf("Accepted,Test point#%d,Use time %.0lfms\n",T,ed-st); } }
end-