zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    ride关键字
    怎么分析《软件需求文档》
    linux系统在线搭建禅道
    用fiddler不能抓取https及证书无法导出
    mybatis There is no getter for property named 'xx' in 'class java.lang.String
    GMT与UTC
    cron表达式详解
    hdu 2083 简易版之最短距离
    hdu 2070 Fibbonacci Number
    hdu 2076 夹角有多大(题目已修改,注意读题)
  • 原文地址:https://www.cnblogs.com/Q1143316492/p/9286090.html
Copyright © 2011-2022 走看看