ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

有关对拍

2022-07-09 09:03:56  阅读:133  来源: 互联网

标签:... include int 有关 freopen txt data


有关对拍

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

基本写法:

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

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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有