对拍代码
windows版本
1.random(随机数)
#include <bits/stdc++.h>
using namespace std;
long long random(int n){
return (1LL<<15)*rand()+rand();
}
//rand()的返回值为[0,RAMD_MAX)的整数;
//注意 windows中RAND_MAX的值为32767;
int main()
{
freopen("a.in","w",stdout);
srand((unsigned)time(NULL));
int n=rand()%101,m=rand()%101;//[0,100]随机整数
printf("%d %d\n",n,m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int x=rand()%200-100;//x范围(-100,+100)
printf("%d ",x);
}
printf("\n");
}
return 0;
}
2.dp(对拍)
记得在对拍的两个代码中加freopen();
#include <bits/stdc++.h>
using namespace std;
/*#include <cstdlib>
#include <cstdio>
#include <ctime>*/
//对拍
int main()
{
/* system是执行系统指令 返回值 0 表示
顺利执行;返回值 1 表示未顺利执行。*/
//编译
system("g++ a.cpp -o a");//-std=c++14
system("g++ b.cpp -o b");
system("g++ random.cpp -o random");
for(int T=1;T<=1000;T++)
{
system("random.exe");
double st=clock();
system("a.exe");//执行a
double ed=clock();
system("b.exe");//执行b
if(system("fc a.out b.out")){//对拍
puts("Wrong Answer");//有返回值
return 0;
}
else{
printf("Ac, %d,time: %.0lfms\n",T,ed-st);
}
}
}
noi Linux
1.random(与windows相同)
#include <bits/stdc++.h>
using namespace std;
long long random(int n){
return (1LL<<15)*rand()+rand();
}
//rand()的返回值为[0,RAMD_MAX)的整数;
//注意 linux中RAND_MAX值为2147483647;
int main()
{
freopen("a.in","w",stdout);
srand((unsigned)time(NULL));
int n=rand()%101,m=rand()%101;//[0,100]随机整数
printf("%d %d\n",n,m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int x=rand()%200-100;//x范围(-100,+100)
printf("%d ",x);
}
printf("\n");
}
return 0;
}
2.dp
不用在俩代码中加freopen() (真好用QAQ)
#include <bits/stdc++.h>
using namespace std;
/*#include <cstdlib>
#include <cstdio>
#include <ctime>*/
//对拍
int main()
{
system("g++ a.cpp -o a -std=c++14");//-std=c++14编译方式,可以快点
system("g++ b.cpp -o b -std=c++14");
system("g++ random.cpp -o random -std=c++14");
for(int T=1;T<=1000;T++)
{
system("./random >a.in");
double st=clock();
system("./a < a.in > a.out");
double ed=clock();
system("./b < a.in > a.out");
if(system("diff a.out b.out")){
puts("Wrong Answer\n");
return 0;
}
else{
printf("AC, %d,time: %.0lfs\n",T,ed-st);
}
}
}