对拍,分为《自动对拍》和《手动对拍》,基础材料都是暴利解和尝试的正解程序,造数据这块,可以系统自动生成,也可以手动人为构造数据。
生成数据
// gen.cpp
#include <bits/stdc++.h>
using namespace std;
int rnd(int l, int r){
return l + rand() % (r - l + 1);
}
int main(){
freopen("data.in", "w", stdout);
srand((int)time(0));
printf("%d %d\n", rnd(30, 50), rnd(70, 90));
return 0;
}
暴力程序和优化程序
// A.cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("data.in", "r", stdin);
freopen("A.out", "w", stdout);
int a, b;
cin >> a >> b;
cout << a + b << '\n';
return 0;
}
// B.cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("data.in", "r", stdin);
freopen("B.out", "w", stdout);
int a, b;
cin >> a >> b;
cout << a - b << '\n';
return 0;
}
对拍程序
// duipai.cpp
// linux下演示, diff命令
// Windows下,是fc命令 system("fc A.out B.out");
// cmd终端暂停查看,system("pause");
#include <bits/stdc++.h>
using namespace std;
int main(){
int T = 10;
for (int i = 1; i <= T; i++){
system("./gen");
system("./A");
system("./B");
if (system("diff A.out B.out")){
printf("WA on test%d\n", i);
return 0;
}
else{
printf("AC on test%d\n", i);
}
}
return 0;
}