其他分享
首页 > 其他分享> > 有关对拍

有关对拍

作者:互联网

有关对拍

不得不说,对拍真的是一个调试程序的好方法,当然还是要结合自已睿智的脑子...

基本写法:

你需要将这些文件放到同一个目录下:

duipai.cpp | freopen: Result.txt(stdout)

sol.cpp | freopen: data.txt(stdin), myans.txt(stdout)

bf.cpp | freopen: data.txt(stdin), stdans.txt(stdout)

rand.cpp | freopen: data.txt(stdout)

\(1.\) 对拍程序:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

signed main() {
    freopen("Ans.txt", "w", stdout);
    for(int T = 1; T <= 30; T++) { // 注意设置路径
        system("D:\\rand.exe"); // -> data.txt
        double st = clock();
        system("D:\\sol.exe"); // data.txt -> sol.exe -> myans.txt
        double ed = clock();
        system("D:\\bf.exe"); // data.txt -> bf.exe -> stdans.txt
        if(system("fc D:\\myans.txt D:\\stdans.txt")) {
            printf(">>> Wrong Answer on test case #%d!", T);
            return 0; // 返回 Wrong Answer 时,data.txt 即为发生错误的样例
        }
        else printf("Accepted on test case #%d, time usage %.2lfms\n", T, ed - st);
    }
}

注意这些程序一定要经过编译得到 \(\rm .exe\) 文件才行!

\(2.\) 随机样例生成程序:

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <map> 
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e6 + 5;

inline int random(int x) {
	return (LL)rand() * rand() % x;
}

signed main() {
	//freopen("sets.txt", "r", stdin);
	freopen("data.txt", "w", stdout);
	srand((unsigned)time(0));
	// ... ... ...
}

其中常见的有随机整数,随机区间,随机树,随机图等等。

昨天晚上用过的随机图:(有向图,无重遍和自环)

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e6 + 5;

pair <int, int> e[N];
map < pair <int, int>, bool> h;

inline int random(int x) {
	return (LL)rand() * rand() % x;
}

signed main() {
	//freopen("sets.txt", "r", stdin);
	freopen("data.txt", "w", stdout);
	srand((unsigned)time(0));
	int n, m; LL txn;
	n = random(120) + 200;
	m = random(200) + 350;
	txn = 1e9;
	cout << n << ' ' << m << ' ' << txn << endl;
	for(int i = 1; i < n; i++) {
		int fa = random(i) + 1;
		e[i] = make_pair(fa, i + 1);
		h[e[i]] = true;
	}
	for(int i = n; i <= m; i++) {
		int x, y;
		do {
			x = random(n) + 1, y = random(n) + 1;
		} while(x == y || h[make_pair(x, y)]);
		e[i] = make_pair(x, y);
		h[e[i]] = true;
	}
	random_shuffle(e + 1, e + m + 1);
	for(int i = 1; i <= m; i++)
		cout << e[i].first << ' ' << e[i].second << endl;
	return 0;
}

\(3.\) \(\text{sol.cpp}\)

自己打的要检测的程序:

#include <bits/stdc++.h>
#define def LL
#define LL long long
using namespace std;
const int N = 3e5 + 5;

/*
... ... ...
*/

signed main() {
#ifndef ONLINE_JUDGE
    freopen("data.txt", "r", stdin);
    freopen("myans.txt", "w", stdout);
#endif
    // ... ... ...
}

\(4.\) \(\text{bf.cpp}\)

自己写的暴力(保证正确性的)程序,或者抄来的别人的正解。

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5,M=1e6+5;

/*
... ... ...
*/

int main(){
	freopen("data.txt", "r", stdin);
	freopen("stdans.txt", "w", stdout);
    /// ... ... ...
}

大概就是这样了。。。

标签:...,include,int,有关,freopen,txt,data
来源: https://www.cnblogs.com/Doge297778/p/16460111.html