因为写欧拉函数所以学会的简单对拍
1.随机生成数据:
1.随机生成一个数:
非常简单啦也是,这里的mod取决于你要生成的数最大想要多大;
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.随机生成整数序列:
随机生成n<=10e5个绝对值在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.随机生成区间列:
随机生成m个[1,n]的子区间,这些区间可作为数据结构题目的操作序列;
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.随机生成树:
随机生成一棵n个点的树,用n个点n-1条边的无向图的形式输出,每条边附带一个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.随机生成图:
随机生成一张n个点m条边的无向图,图中不存在重边,自环,且必须联通。保证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); } }
然后写一套暴力命名为bf.cpp,一套你认为的正解命名为sol.cpp,然后将其编译,注意要写freopen,同时放到一个文件夹下面(应该吧)(这里直接放到C:了),然后运行以下程序:
不管怎样一定要保存的运行:
#include<cstdlib> #include<cstdio> #include<ctime> int main(){ for(int T=1;T<=次数;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,测试点#%d,用时 %.0lfms\n",T,ed-st); } }
end-