对拍
- 使用随机数提供数据
如下代码gen.cpp,产生 \(n\) 个 \(-1\) 和 \(1\) 的随机数,编译生成gen.exe。
#include <iostream>
#include <random>//rand()最大32767
using namespace std;
mt19937 d1(random_device{}());
const int N = 3e4 + 7;
int a[N];
int main() {
int n = d1() % 20;
printf("%d\n", n);
for (int i = 1; i <= n; ++i) {
int x = d1()%2;
if (!x) x = -1;
printf("%d ", x);
}
return 0;
}
- 分别写出测试程序
TT.exe以及标程lec.exe,使用批处理程序对拍.bat测试,代码如下:
@echo off
:loop
gen > 1.in
TT < 1.in > 1.out
lec < 1.in > 1.ans
fc 1.out 1.ans
if not errorlevel 1 goto loop
pause
goto loop
所有程序文件均放在同一个文件夹下,然后双击 对拍.bat 开始测试。
- Linux
#!/bin/bash
while true; do
./rand > input
./baoli < input > baoli.out
./hao < input > hao.out
diff -b baoli.out hao.out
if [ $? -ne 0 ]; then break; fi
done

浙公网安备 33010602011771号