- 新版
- LightOJ - 1138">例题,Trailing Zeroes (III) LightOJ - 1138
- 旧版
对拍,分为《自动对拍》和《手动对拍》,基础材料都是暴利解和尝试的正解程序,造数据这块,可以系统自动生成,也可以手动人为构造数据。
对拍,在提高组高分阶段是有用的,在普及组阶段,使用甚少。
参考:https://www.cnblogs.com/EdisonBa/p/13509379.html
新版
例题,Trailing Zeroes (III) LightOJ - 1138
// duipai.cpp
#include <bits/stdc++.h>
//#include <unistd.h>
using namespace std;
int main(){
int T = 50;
system("g++ -o gen gen.cpp");
system("g++ -o baoli baoli.cpp");
system("g++ -o std A.cpp");
for (int i = 1; i <= T; i++){
system("./gen > data.in");
system("./baoli < data.in > baoli.out");
system("./std < data.in > std.out");
if (system("diff baoli.out std.out")){
printf("WA on test %d\n", i);
return 0;
}
else{
printf("AC on test %d\n", i);
}
//sleep(1);
//usleep(500);
}
return 0;
}
// gen.cpp
#include <bits/stdc++.h>
using namespace std;
int rnd(int l, int r){
return l + rand() % (r - l + 1);
}
int main(){
//freopen("data.in", "w", stdout);
srand((int)time(0));
int T = rnd(1, 5);
printf("%d\n", T);
while (T--){
printf("%d\n", rnd(1, 1e2));
}
return 0;
}
// baoli.cpp
#include <bits/stdc++.h>
using namespace std;
int T, q;
int check(int x){
int t = 0;
while (x){
t += x / 5;
x /= 5;
}
return t;
}
int main(){
//freopen("data.in", "r", stdin);
//freopen("baoli.out", "w", stdout);
//cout << check(1e9) << '\n';
cin >> T;
for (int i = 1; i <= T; i++){
cin >> q;
int j;
for (j = 1; j <= 1e5; j++){
if (check(j) == q) break;
}
if (check(j) == q) printf("Case %d: %d\n", i, j);
else printf("Case %d: impossible\n", i);
}
return 0;
}
// A.cpp
#include <bits/stdc++.h>
using namespace std;
int T, q;
int check(int x){
int t = 0;
while (x){
t += x / 5;
x /= 5;
}
return t;
}
int main(){
//freopen("data.in", "r", stdin);
//freopen("std.out", "w", stdout);
//cout << check(1e9) << '\n';
cin >> T;
for (int i = 1; i <= T; i++){
cin >> q;
int l = 0, r = 1e9, best = -1;
while (l <= r){
int mid = (l + r) >> 1;
if (check(mid) >= q){
best = mid;
r = mid - 1;
}
else{
l = mid + 1;
}
}
if (check(best) == q) printf("Case %d: %d\n", i, best);
else printf("Case %d: impossible\n", i);
}
return 0;
}
旧版
生成数据
// gen.cpp
#include <bits/stdc++.h>
using namespace std;
int rnd(int l, int r){
return l + rand() % (r - l + 1);
}
int main(){
freopen("data.in", "w", stdout);
srand((int)time(0));
printf("%d %d\n", rnd(30, 50), rnd(70, 90));
return 0;
}
暴力程序和优化程序
// A.cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("data.in", "r", stdin);
freopen("A.out", "w", stdout);
int a, b;
cin >> a >> b;
cout << a + b << '\n';
return 0;
}
// B.cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("data.in", "r", stdin);
freopen("B.out", "w", stdout);
int a, b;
cin >> a >> b;
cout << a - b << '\n';
return 0;
}
对拍程序
// duipai.cpp
// linux下演示, diff命令
// Windows下,是fc命令 system("fc A.out B.out");
// cmd终端暂停查看,system("pause");
#include <bits/stdc++.h>
using namespace std;
int main(){
int T = 10;
for (int i = 1; i <= T; i++){
system("./gen");
system("./A");
system("./B");
if (system("diff A.out B.out")){
printf("WA on test%d\n", i);
return 0;
}
else{
printf("AC on test%d\n", i);
}
}
return 0;
}