• 《特殊数据生成》


    在折腾了一天的cyaron还是无法正常运行,我觉得自己来写一份c++的数据生成总和。

    1:有向无环图。(可能有重边)

    bool vis[N];
    map<pii,int> mp;
    void DAG(int maxn,int maxm) {
        freopen("data3.in","w",stdout);
        srand(time(NULL));
        int n = rand() % maxn + 1;
        int m = min(maxm,n * n / 20);
        printf("%d %d
    ",n,m);
        int now = 1;
        while(1) {
            vis[now] = 1;
            int num = rand() % (n - 1) + 1;
            if(n * (n - now) < m / 2) num = n - now;
            for(int i = 1;i <= num && m > 0;++i) {
                int x = rand() % (n - now) + now + 1;
                printf("%d %d
    ",now,x);
                mp[pii(now,x)] = 1;
                m--;
            }
            if(m == 0) break;
            now = rand() % n + 1;
            while(vis[now]) now = rand() % n + 1;
        }
    }
    View Code

    2:树

    vector<int> vec1,vec2;
    void Tree() {
        srand(time(NULL));
        int n = rand() % N + 1;
        printf("%d
    ",n);
        for(int i = 1;i <= n;++i) vec2.push_back(i);
        vec1.push_back(1);
        vec1.push_back(2);
        vec2.erase(vec2.begin());
        vec2.erase(vec2.begin());
        printf("1 2
    ");
        for(int i = 2;i < n;++i) {
            int x = rand() % vec1.size();
            int y = rand() % vec2.size();
            printf("%d %d
    ",vec1[x],vec2[y]);
            vec1.push_back(vec2[y]);
            vec2.erase(vec2.begin() + y);
        }
        for(int i = 1; i <= n;++i) {
            int x = rand() % N + 1;
            printf("%d
    ",x);
        }
    }
    View Code
  • 相关阅读:
    关于session
    信息查找界面
    Java8 新特性 (三)Java内置的函数式接口
    第二节:表的管理
    【LeetCode-数组】有序数组中的单一元素
    【LeetCode-字符串】一次编辑
    【LeetCode-贪心】跳跃游戏 II
    【LeetCode-数组】三个数的最大乘积
    学习进度条94
    学习进度条93
  • 原文地址:https://www.cnblogs.com/zwjzwj/p/14533927.html
Copyright © 2020-2023  润新知