あいさか たいがblogAisaka_Taiga的博客
//https://img2018.cnblogs.com/blog/1646268/201908/1646268-20190806114008215-138720377.jpg

考前必备fa宝——对拍

Toretto·2022-11-25 09:49·292 次阅读

考前必备fa宝——对拍

2022.11.24:晚上zxs学长发来了他的博客,所以我仿照写一篇。
https://www.cnblogs.com/Dita/p/duipai.html

对拍#

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

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

Copy
#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; }

然后就是正解代码

Copy
#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

Copy
#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; }

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

Copy
#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; }

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

posted @   北烛青澜  阅读(292)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示
目录