杂项

  • 数据生成
#include <bits/stdc++.h>
using namespace std;

signed main() {
    mt19937_64 rd(chrono::system_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> dis(1e7, 1e9);

    for (int i = 1; i <= 10; i++) {
        string IN = "coin" + to_string(i) + ".in";
        ofstream out(IN.c_str());
        out << dis(rd) << endl;
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

signed main(int argc, char *argv[]) {
    int n = stoi(argv[1]);

    mt19937_64 rd(chrono::system_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> dis(1e7, 1e9);

    ofstream data("data.in");
    data << n << ' ' << n << '\n';
    for (int i = 1; i <= n; i++) data << rd() % n + 1 << " \n"[i == n];
    for (int i = 1; i <= n; i++) {
        int op = rd() % 2 + 1;
        if (op == 2) {
            data << op << '\n';
        } else {
            int x = rd() % n + 1, y = rd() % n + 1;
            data << op << ' ' << x << ' ' << y << '\n';
        }
    }
    return 0;
}
  • 对拍
#include <bits/stdc++.h>
using namespace std;

signed main(int argc, char *argv[]) {
    int T = stoi(argv[1]);
    for (int t = 1; t <= T; t++) {
        assert(!system(("./makedata " + string(argv[2])).c_str()));

        assert(!system("./test1"));
        ifstream myO("test.out");
        vector<string> myA; string myS;
        while (getline(myO, myS)) myA.push_back(myS);

        assert(!system("./std"));
        ifstream stdO("std.out");
        vector<string> stdA; string stdS;
        while (getline(stdO, stdS)) stdA.push_back(stdS);

        if (myA != stdA) {
            cerr << "Case " << t << "WA!" << endl;
            if (myA.size() != stdA.size()) {
                cerr << "mySz = " << myA.size() << ", stdSz = " << stdA.size() << endl;
            }
            else {
                for (size_t i = 0; i < myA.size(); i++) {
                    if (myA[i] != stdA[i]) {
                        cerr << "line " << i + 1 << endl;
                        cerr << "myA = " << myA[i] << ", stdA = " << stdA[i] << endl; exit(0);
                    }
                }
            }
            exit(0);
        }
        else cerr << "Case " << t << "AC" << endl;
    }
    return 0;
}
  • bash
g++ test1.cpp -o test1 -std=c++14 -O2 -Wall -fsanitize=address,undefined && /usr/bin/time -f "%es, %MKB" ./test1
posted @ 2024-02-08 23:39  wkh2008  阅读(31)  评论(0编辑  收藏  举报