对拍
对拍
对拍程序
#include <bits/stdc++.h>
using namespace std;
int main(){
for(int i=1;i<=100000;i++){
system("mk");
system("my < in.txt > my.out");//my 和 std可替换成自己的程序名
system("std < in.txt > std.out");
if(system("fc my.out std.out")){//windows下是fc,linux是diff
puts("!!!!!!");
while(1);
}
}
return 0;
}
mk(造数据)
大体框架
#include <bits/stdc++.h>
using namespace std;
const int N=30000;
const int inf=1e9;
int main(){
int seed;
freopen("seed.txt", "r", stdin);
scanf("%d",&seed);
srand(seed+time(0));
for(int i=0;i<5;i++) rand();
freopen("seed.txt", "w", stdout);
printf("%d\n",rand());
freopen("in.txt","w",stdout);
int n=rand()%N;
printf("%d\n",n);
for(int i=1;i<=n;i++)
printf("%d ",rand()%n);
return 0;
}
无向图:
#include <cstdio>
#include <ctime>
#include <algorithm>
using namespace std;
int vis[1000][1000];
const int N=1e6+10;
int main(){
int seed;
freopen("seed.txt", "r", stdin);
scanf("%d",&seed);
srand(seed+time(0));
for(int i=0;i<5;i++) rand();
freopen("seed.txt","w",stdout);
printf("%d\n", rand());
freopen("in.txt","w",stdout);
int t=rand()%10;
while(t--){
int n=rand()%N;
int m=rand()%(5*N);
printf("%d %d\n",n,m);
for(int i=1;i<=n;i++)
printf("%d ",rand()%10000);
for(int i=1;i<=m;i++){
int x=1,y=1;
while(x==y || vis[x][y]){
x = rand()%n+1;
y = rand()%n+1;
}
vis[x][y] = vis[y][x] = 1;// wuxiangtu
printf("%d %d\n",x,y);
}
}
return 0;
}
树:
while(cnt<n-1){
int x=rand()%n+1;
int y=rand()%n+1;
int xx=find(x);
int yy=find(y);
if(xx==yy)continue;
f[xx]=yy;++cnt;
cout<<x<<" "<<y<<endl;
}
简易方法:
for(int i=1;i<n;i++)
printf("%d %d\n",i,rand()%(i-1)+1);