考前必备fa宝——对拍

2023-07-29,,

2022.11.24:晚上zxs学长发来了他的博客,所以我仿照写一篇。

https://www.cnblogs.com/Dita/p/duipai.html

对拍

对拍这个东西,就是可以比较两份代码跑出来的答案的一个程序,通常是你的代码和标称对比或者你考试时写的你认为的正解与暴力对比,可以给自己写出来过了那极水的样例的代码找找hack。一般我都不写,主要是不会(。

首先我们需要一个暴力程序,就拿最简单的a+b问题来说

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
freopen("55.in","r",stdin);
int a,b,ans=0;
cin>>a>>b;
for(int i=1;i<=a;i++)
ans++;
for(int i=1;i<=b;i++)
ans++;
cout<<ans<<endl;
return 0;
}

然后就是正解代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
freopen("55.in","r",stdin);
int a,b;
cin>>a>>b;
cout<<(int)(a+b)<<endl;
return 0;
}

生成数据点得代码

表示生成的数据范围是1-1e8

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
freopen("55.in","w",stdout);
srand(time(0));
int a=rand()%100000000+1;
int b=rand()%100000000+1;
cout<<a<<" "<<b<<endl;
return 0;
}

接下来我们需要写对拍程序

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int T=1e6;
while(T--)
{
system("shujv.exe > shujv.txt");
system("baoli.exe < shujv.txt > baoli.txt");
system("std.exe < shujv.txt > std.txt");
if(system("fc baoli.txt std.txt"))break;
}
if(T==0)cout<<"NO ERROR"<<endl;
else cout<<"ERROR"<<endl;
return 0;
}

然后先运行一遍数据的程序,然后运行两个你写的程序,最后运行对拍程序,就可以了

考前必备fa宝——对拍的相关教程结束。

《考前必备fa宝——对拍.doc》

下载本文的Word格式文档,以方便收藏与打印。