写在前面:最近几天看蒋老师直接使用了Sublime中的FastOlympicCode插件进行了对拍,出于兴趣来学习一下,关于插件的配置已经有很多大佬讲过啦,这里不再赘述。数据生成的代码我会放到最后,包括生成数组、区间、树、图。
首先,如果我们需要对d.cpp
这个文件进行对拍,就需要创建d__Good.cpp
和d__Generator.cpp
两个文件,顾名思义,前者是正确代码,而后者是数据生成的代码,注意两个文件中都带有两个下划线。
然后,我们在需要对拍的文件中按下ctrl+shift+p
找到FastOlympicCoding:Make Stress
然后回车即可,下图表示程序正在编译
编译完成后,对拍进行过程如下图所示,找到错误数据后对拍会自动暂停。
这里给出一份生成数据的代码,可以生成数组、区间、树、图,供大家参考。
如有错误欢迎您及时向我指出。
#include using i64 = long long; std::mt19937 rnd(std::chrono::steady_clock().now().time_since_epoch().count()); int rng(int l, int r) { // [l, r] return rnd() % (r - l + 1) + l; } void array(int n) { // Generates an array with n elements int m = 1E9; std::vector a(n); for (int i = 0; i < n; i++) { a[i] = rng(0, m); std::cout << a[i] << " \n"[i == n - 1]; } } void cand(int m, int n) { // Generate m cands from 1 to n for (int i = 0; i < m; i++) { int l = rng(1, n); int r = rng(1, n); if (l > r) { std::swap(l, r); } std::cout << l << " " << r << "\n"; } } void tree(int n) { // Generate a tree with n vertices int m = 1E9; for (int i = 1; i < n; i++) { int p = rng(0, i - 1); int v = rng(1, m); std::cout << p + 1 << " " << i + 1 << " " << v << "\n"; } } void graph(int n, int m) { // Generate an undirected graph with n vertices and m edges. There are no double edges or self-rings in the graph, and must be connected. std::vector> e; std::map, bool> f; std::cout << n << " " << m << "\n"; for (int i = 1; i < n; i++) { int p = rng(0, i - 1); e.push_back(std::make_pair(p, i)); f[std::make_pair(p, i)] = f[std::make_pair(i, p)] = true; } // debug(f); for (int i = n; i <= m; i++) { int x, y; do { x = rng(0, n - 1); y = rng(0, n - 1); } while (x == y || f.count(std::make_pair(x, y))); e.push_back(std::make_pair(x, y)); f[std::make_pair(x, y)] = f[std::make_pair(y, x)] = true; } std::shuffle(e.begin(), e.end(), rnd); for (auto [x, y] : e) { std::cout << x + 1 << " " << y + 1 << "\n"; } } int main() { int t = 5; std::cout << t << "\n"; while (t--) { graph(3, 3); } return 0; }