今天我们来看一下对拍
对拍是经常用的技巧,拥有在写了暴力后与标程比较比较看看自己的是否正确等等用途
对拍需要的四个物品
baoli.exe , std.exe , date.exe , pai.exe
现在让我们看看具体怎么操作
第一步:一个你的暴力程序
需要cpp生成一个exe才可以
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("data.txt","r",stdin);
freopen("baoli.out","w",stdout);
int n;cin>>n;
int tot=0;
for(int i=1;i<=n;i++)
{
int x;cin>>x;
tot+=x;
}
cout<<tot;
}
第二步:一个std.exe
当然一个std的exe也是必不可少的
#include<bits/stdc++.h>
using namespace std;
int main()
{
srand(time(0));
freopen("data.txt","r",stdin);
freopen("std.out","w",stdout);
int n;cin>>n;
int tot=0;
for(int i=1;i<=n;i++)
{
int x;cin>>x;
tot+=x;
}
int t=rand()%3;
if(t==0) tot++;
cout<<tot;
}
第三步:数据生成
再生成两个exe之后我们准备比较
现在我们看一下数据生成器
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("data.txt","w",stdout);
srand(time(0));
int n=rand()%100+1;
cout<<n<<endl;
for(int i=1;i<=n;i++)
{
int a=rand()%1000+1;
cout<<a<<" ";
}
}
当然这些具体的内容因题目而异,需要自己去调整
第四步:对拍器
最后需要的是对拍器
对拍的直接实现核心
#include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
int main()
{ int tot=0;
while(true)
{
system("data.exe");
system("std.exe");
system("baoli.exe");
if(system("fc std.out baoli.out"))
{
cout<<"WA";
while(1);
system("pause");
}
tot++;
cout<<tot;
}
}
第五步:运行pai.exe,查看结果
所谓对拍就是这样的东西啦,不过每个部分的具体内容需要自己去修改研究,本篇博客中的仅仅是个样例而已233333