关于对拍
被折磨挺久了的,估计是我 vscode 配置的问题,运行对拍文件的时候总是报错,找了很久的问题解决了,写个板子在这里自己用。
Windows环境下的对拍:
四份代码
初始:
正解,暴力代码不用说。先写两份出来。
随机函数:
#include <bits/stdc++.h>
using namespace std;
const int N=101010;
int main(){
srand(unsigned(time(0)));
int l,r; //自行定义范围
int a=rand()%(r-l+1)+l;
//生成 [l,r] 之间的数
}
对拍代码:
#include<bits/stdc++.h>
using namespace std;
const int N=101010;
int main(){
long s,t;
while(1){
system("C:\\qwqcodefield\\duipai\\bin\\rand.exe");
//生成数据,正常放同一文件夹下,不用写完整路径
s=clock();
system("C:\\qwqcodefield\\duipai\\bin\\t1.exe");
t=clock();//你以为的正解
system("C:\\qwqcodefield\\duipai\\bin\\check.exe");
//比对输出
if(system("fc first.out second.out")){
cout<<"Wa"<<endl;
cout<<t-s<<"ms"<<endl;
break;
}
else {
cout<<"Ac"<<endl;
}
}
}
值得注意的是,跑对拍前,应把前三份代码重新编译生成 exe 文件。
然后在正解,和暴力里 freopen 进随机数据就好,再 freopen 出输出比对就行。
Linus 环境下的对拍:
把这份改一改就好了。
对拍代码:
#include<bits/stdc++.h>
using namespace std;
const int N=101010;
int main(){
long s,t;
while(1){
system("./rand");
//生成数据,正常放同一文件夹下,不用写完整路径
s=clock();
system("./t1");
t=clock();//你以为的正解
system("./check");
//比对输出
if(system("diff first.out second.out")){
cout<<"Wa"<<endl;
cout<<t-s<<"ms"<<endl;
break;
}
else {
cout<<"Ac"<<endl;
}
}
}