跳到正文

算法·理论

对拍程序

ZZloveMY约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年10月31日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 2 分钟

版本

  1. v1当前

赛时样例太少或太弱怎么办,这时就需要对拍程序了。 它也可以用来hack或验证正确性。

对拍时我们需要四个程序,分别是:

  1. random.cpp(生成数据)

模板code:

C++
#include<bits/stdc++.h>
using namespace std;
//mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());质量高但难记
mt19937_64 rd(time(0));//方便直接

signed main(){
	freopen("_test.in","w",stdout);
	ios::sync_with_stdio(0);
	cout.tie(0);
	int n=rd()%10;//%来保证数据范围,较小的数据方便自己改
	/*
	根据题目来输出测试数据
	*/
	return 0;
}
  1. baoli.cpp(暴力代码)
C++
#include<bits/stdc++.h>
using namespace std;

signed main(){
	freopen("_test.in","r",stdin);
	freopen("baoli.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
    //...
	return 0;
}
  1. solve.cpp(需调试的代码)
C++
#include<bits/stdc++.h>
using namespace std;

signed main(){
	freopen("_test.in","r",stdin);
	freopen("solve.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
    //...
	return 0;
}
  1. duipai.cpp(对拍代码)
C++
#include<bits/stdc++.h>
using namespace std;

signed main(){
	while(1){
		system("random.exe");//运行数据程序
		system("baoli.exe");//运行暴力程序
		system("solve.exe");//运行调试程序
		if(system("fc /n baoli.out solve.out")){
			cout<<"WA";
			getchar();//暂停
		}//fc 对比输出数据的区别 /n 输出不一样的行号
	}
	return 0;
}
原文