码迷,mamicode.com
首页 > 其他好文 > 详细

浴谷国庆集训 对拍

时间:2017-10-15 23:16:46      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:如图所示   using   程序   logs   unsigned   src   null   images   超时   

今天晚上集训ltt讲了 Linux 的简单操作和对拍,这里做一个简单的对拍笔记。

先来假设一个情景。现在是 NOIP 考试当中,有一道极难的 dp 题目,我无法证明它是否正确,但我能写出一个会超时但保证正确的暴力程序。

假设这段程序是要测试的 dp 程序 program.cpp:

 1 #include <iostream>
 2 #include <cstdlib>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <cstring>
 6 using namespace std;
 7 int main()
 8 {
 9     freopen("rand.out","r",stdin);
10     freopen("program.out","w",stdout);
11     int a,b;
12     cin >> a >> b;
13     if (a == 1)
14         cout << a+b << endl;
15     else
16         cout << a << endl;
17     return 0;
18 }

 

(显然这时错误的)

还有保证正确的暴力程序 std.cpp:

 1 #include <iostream>
 2 #include <cstdlib>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <cstring>
 6 using namespace std;
 7 int main()
 8 {
 9     freopen("rand.out","r",stdin);
10     freopen("std.out","w",stdout);
11     int a,b;
12     cin >> a >> b;
13     cout << a+b << endl;
14     return 0;
15 }

(一定正确的“暴力解法”)

再写一个随机生成数据的 rand.cpp:

 1 #include <iostream>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 using namespace std;
 5 int main()
 6 {
 7     freopen("rand.out","w",stdout);
 8     srand((unsigned)time(NULL));  
 9     cout << rand() << endl;
10     cout << rand() << endl;
11     return 0;
12 }

随机生成两个数据,将其输出在 rand.out 中。

然后在 std.cpp 和 program.cpp 中分别调用 rand.out 中随机生成的两个数据。

新建一个 cmd 文件,输入以下代码:

1 @echo off
2 :flag
3 rand.exe
4 program.exe
5 std.exe
6 fc program.out std.out
7 if not errorlevel 1 goto flag
8 pause

这段代码中,先执行随机生成数据,然后调用两个程序,最后利用 fc 比对 program.out 和 std.out 中的输出数据。

技术分享

效果如图所示(这个批处理是另一位老师实现的,但是效果类似),发现错误后,可以在 rand.out 中找到让两个程序出现不同的数据,然后进行调试。

以上是有关对拍的笔记。

浴谷国庆集训 对拍

标签:如图所示   using   程序   logs   unsigned   src   null   images   超时   

原文地址:http://www.cnblogs.com/OIerPrime/p/7674663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!