在 OI 赛制 中,代码只能交一次,这是比赛与 OJ 最大的不同。我们如果不能保证代码是正确的,就需要对拍:
-
code1/2.cpp:暴力及正解代码。
-
random.cpp:随机数据生成器。
-
match.cpp:对拍程序:
一. 对拍程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #include<cstdio> #include<cstdlib> int T = 100; signed main() { while (T--) { system("./random > in.txt"); system("./1 < in.txt > 1.txt"); system("./2 < in.txt > 2.txt"); if (system("diff -b 1.txt 2.txt")) { printf("Error!!!\n"); exit(1); } else { printf("Ok\n"); } } }
|
注意头文件。
二. 随机数程序
主推 mt19937 (需要 c++11)。随机数范围到 219937−1。完全不用担心不够用,具体实例:
1 2 3 4 5 6 7
| #include<random> #include<ctime> using namespace std; mt19937 rd(time(0)); int random(int l, int r) { return rd() % (r - l + 1) + l; }
|
三. 图像示例