跳到正文

个人记录

关于Windows下的对拍

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

文章信息

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

版本

  1. v1当前

对拍是什么,对拍实际上是一种用一道题暴力(一定正确,时间复杂度不重要)的程序来检验你写的正解(你认为可以AC的代码)。

下面放上我常在Windows上常用的对拍器

C++
#include<bits/stdc++.h>
using namespace std;
int main() {
	system("g++ datamaker.cpp -o datamaker.exe");
	cout << "datamaker compiled" << endl;
	system("g++ std.cpp -o std.exe");
	cout << "std compiled" << endl;
	system("g++ yours.cpp -o yours.exe");
	cout << "yours compiled" << endl;
	int T = 0;
	while (++T) {
		cout << "[info] testdata<" << T << ">" << endl;
		double a = clock() / 1000.0;
		system("datamaker.exe > data.in");
		double b = clock() / 1000.0;
		cout << "[info] data made in " << b - a << "s" << endl;
		system("std.exe < data.in > exp.out");
		double c = clock() / 1000.0;
		cout << "[info] std finished in " << c - b << "s" << endl;
		system("yours.exe < data.in > yours.out");
		double d = clock() / 1000.0;
		cout << "[info] yours finished in " << d - c << "s" << endl;
		system("type data.in");  //输出测试用例。
		if (system("fc exp.out yours.out")) {  //比较正解和暴力的输出一不一样。
			break;
		}
	}
}

这里面的datamaker.cpp为数据生成器,std.cpp为暴力代码,yours.cpp就是你的正解程序。

原文
存档评论1 条抓取于