对拍,分为《自动对拍》和《手动对拍》,基础材料都是暴利解和尝试的正解程序,造数据这块,可以系统自动生成,也可以手动人为构造数据。

对拍,在提高组高分阶段是有用的,在普及组阶段,使用甚少。

image.png

生成数据

  1. // gen.cpp
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int rnd(int l, int r){
  5. return l + rand() % (r - l + 1);
  6. }
  7. int main(){
  8. freopen("data.in", "w", stdout);
  9. srand((int)time(0));
  10. printf("%d %d\n", rnd(30, 50), rnd(70, 90));
  11. return 0;
  12. }

暴力程序和优化程序

  1. // A.cpp
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int main(){
  5. freopen("data.in", "r", stdin);
  6. freopen("A.out", "w", stdout);
  7. int a, b;
  8. cin >> a >> b;
  9. cout << a + b << '\n';
  10. return 0;
  11. }
  12. // B.cpp
  13. #include <bits/stdc++.h>
  14. using namespace std;
  15. int main(){
  16. freopen("data.in", "r", stdin);
  17. freopen("B.out", "w", stdout);
  18. int a, b;
  19. cin >> a >> b;
  20. cout << a - b << '\n';
  21. return 0;
  22. }

对拍程序

  1. // duipai.cpp
  2. // linux下演示, diff命令
  3. // Windows下,是fc命令 system("fc A.out B.out");
  4. // cmd终端暂停查看,system("pause");
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. int main(){
  8. int T = 10;
  9. for (int i = 1; i <= T; i++){
  10. system("./gen");
  11. system("./A");
  12. system("./B");
  13. if (system("diff A.out B.out")){
  14. printf("WA on test%d\n", i);
  15. return 0;
  16. }
  17. else{
  18. printf("AC on test%d\n", i);
  19. }
  20. }
  21. return 0;
  22. }