• ACM对拍cpp程序


    ps:参考《算法竞赛进阶指南》

    #include <bits/stdc++.h>
    
    using namespace std;
    const int MAXN = 1e6 + 10;
    
    class RandomData {
    private:
        static const int MAXN = 1e6 + 10;
    public:
        RandomData() {
            srand((unsigned)time(0));
        }
    
        int random(int n) {
            return (long long)rand() * rand() % n;
        }
    
        int random(int l, int r) {
            return random(r - l + 1) + l;
        }
    
        auto random_vector(int n, int val) {
            vector<int>vec;
            for(int i = 1; i <= n; i++ ) {
                vec.push_back(random(n) + val);
            }
            return vec;
        }
    
        auto random_interval(int n, int l, int r) {
            vector<pair<int, int> >vec;
            for(int i = 1; i <= n; i++ ) {
                int L = random(l, r);
                int R = random(l, r);
                if(L > R) {
                    swap(L, R);
                }
                vec.push_back(make_pair(L, R));
            }
            return vec;
        }
    
        auto random_tree(int n, int m, int l = 1, int r = 1) {
            vector<tuple<int, int, int> >vec; //id father_id value
            if(n <= 2) {
                vec.push_back(make_tuple(1, 0, 1));
                return vec;
            }
            for(int i = 2; i <= n; i++ ) {
                int fa = random(i - 1) + 1;
                int val = random(l, r);
                vec.push_back(make_tuple(i, fa, val));
            }
            return vec;
        }
    
        auto random_graph(int n, int m, int l = 1, int r = 1) {
            bool open = 1; // 1 is direct graph and 0 is not
            vector<tuple<int, int, int> >vec = random_tree(n, m, l, r);
            map< pair<int, int>, bool > has;
            for(unsigned i = 0; i < vec.size(); i++ ) {
                int u = get<0>(vec[i]);
                int v = get<1>(vec[i]);
                has[ make_pair(u, v) ] = true;
                if(open == 0) {
                    has[ make_pair(v, u) ] = true;
                }
            }
            for(int i = n; i <= m; i++ ) {
                int x, y;
                do {
                    x = random(n) + 1, y = random(y) + 1;
                } while(x == y || has[ make_pair(x, y) ]);
                int val = random(l, r);
                vec.push_back(make_tuple(x, y, val));
                has[ make_pair(x, y) ] = true;
                if(open) {
                    has[ make_pair(y, x) ] = true;
                }
            }
            random_shuffle(vec.begin(), vec.end());
            return vec;
        }
    } random_data;
    
    void checked(char data[], char sol[], char ans[], char file1[], char file2[]) {
        int T = 10000;
        char cmd[MAXN];
        for(int cas = 1; cas <= T; cas++ ) {
            system(data);
            double st = clock();
            system(sol);
            double ed = clock();
            system(ans);
            strcpy(cmd, "fc ");
            strcat(cmd, file1);
            strcat(cmd, " ");
            strcat(cmd, file2);
            cout << cmd << endl;
            if(system(cmd)) {
                puts("Wrong Answer");
                return ;
            } else {
                printf("Accepted, 测试点 #%d, 用时 %.0f
    ", cas, ed - st);
            }
        }
    }
    
    int main() {
    
    
        return 0;
    }
  • 相关阅读:
    C++-类的const成员变量
    Linux-编译器gcc/g++编译步骤
    C++-理解构造函数、析构函数执行顺序
    Linux-Unix版本介绍
    C++-const_cast只能用于指针和引用,对象的const到非const可以用static_cast
    Linux-如何查看登陆shell的类型
    C++-不要在构造和析构函数中调用虚函数
    C++-模板的声明和实现为何要放在头文件中
    C++-函数模板特化如何避免重复定义
    Linux-Gcc生成和使用静态库和动态库详解
  • 原文地址:https://www.cnblogs.com/Q1143316492/p/9286090.html
Copyright © 2020-2023  润新知