快考试了,希望现在的学习对考试有帮助
这篇笔记主要是从Dita学长这里学到的
考场上我们往往会先敲暴力再敲正解,暴力比正解好敲,正确率也高,唯一的缺点是速度慢了亿点点。敲好了暴力后再敲正解,总有一种辛苦敲出的暴力被浪费的感觉,这时候我们就可以用暴力程序进行对拍
敲出的正解有时难证明正确性,自己造出数据来也不好判断对错,这时候就可以用到对拍
对拍前需要准备好一个当前题目的暴力程序(注意,一定要是确保正确的暴力!!!)
然后写一个数据生成器(介于本人过于蒟蒻,这里copy一下学长的)
大体上长这样:
主要是利用rand
/*
work by: Ariel_
Knowledge:
Time:
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int read() {
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = getchar();}
return x * f;
}
int n, m;
int main(){
freopen("a.in", "w", stdout);
n = rand() % 10 + 1, m = rand() % 10 + 1;
cout<<n<<" "<<m<<"\n";
for (int i = 1; i <= n; i++) {
int x = rand() % n + 1;
while(x == i) {
x = rand() % n + 1;
}
cout<<x<<" ";
}
puts("");
for (int i = 1; i <= n; i++) {
cout<<rand() % 100 + 1<<" ";
}
return 0;
}在暴力代码和“正解”代码里加上
freopen("xxx.in", "r", stdin);注意两个代码的读入文件要相同
调试代码需要用到#include<windows.h>
不在万能头里,需要额外敲
最后写上调试代码(还是copy学长的T_T)
/*
work by: Ariel_
Knowledge:
Time:
*/
#include<windows.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int read() {
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = getchar();}
return x * f;
}
int T = 1e5;
int main(){
while(T--) {
system("rand.exe > rand.txt");
system("baoli.exe < rand.txt > baoli.txt");
system("std.exe < rand.txt > std.txt");
if(system("fc baoli.txt std.txt")) break;
}
if(T == 0) cout<<"no error";
else cout<<"error";
return 0;
}记得把上述程序放到同一文件夹里,防止出现奇奇怪怪的问题
一般来说,因为暴力比较慢,所以对拍先对拍暴力不会Tle的小数据,发现无误后再换大数据。对拍速度可能比较慢,可以在跑对拍的时候去做别的题,一般考试时间还是足够对拍跑完的。