跳到正文

休闲·娱乐

造数据心得

pan_g约 5 分钟
原文
文章信息与版本

文章信息

发布
2024年7月1日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 5 分钟

版本

  1. v1当前

Top Use

C++
# pragma GCC optimize(1, 2, 3, "Ofast", "inline", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
# define endl "\n"
typedef long long ll;
typedef __int128_t bll;
void mk_dir(int id){
    string x = "name" + to_string(id) + ".in";
    auto file = freopen(x.data(), "w", stdout);
    // other things
}
signed main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    srand((unsigned)time(NULL));
    return 0;
}

Spawn Big Integer

C++
ll Rand_int(int bit){
    ll res = 0;
    for(int i = 1;i <= bit;i++) res = (res << 3) + (res << 1) + rand() % 10;
    return res;
}

string Rand_Bigint(int bit){
    string res = "";
    for(int i = 1;i <= bit;i++) res += to_string(rand() % 10);
    reverse(res.begin(), res.end());
    while(res.back() == '0') res.pop_back();
    reverse(res.begin(), res.end());
    return res;
}

Spawn Trees(Includes Chain)

C++
vector<pair<int, int> > do_tree(int n){
    vector<int> f(n);
    iota(f.begin(), f.end(), 1);
    shuffle(f.begin(), f.end(), default_random_engine(time(NULL)));
    vector<pair<int, int> > G;
    for(int i = 1;i < n;i++){
        int fa = f[Rand_int(6) % i];
        G.emplace_back(f[i], fa);
    }
    shuffle(G.begin(), G.end(), default_random_engine(time(NULL)));
    return G;
}
vector<pair<int, int> > do_chain(int n){
    vector<int> f(n);
    iota(f.begin(), f.end(), 1);
    shuffle(f.begin(), f.end(), default_random_engine(time(NULL)));
    vector<pair<int, int> > G;
    for(int i = 1;i < n;i++) G.emplace_back(f[i - 1], f[i]);
    shuffle(G.begin(), G.end(), default_random_engine(time(NULL)));
    return G;
}
vector<pair<int, int> > do_wide_tree(int n){
    int root = Rand_int(6) % n + 1;
    vector<int> dep(n + 1, -1);
    dep[root] = 1;
    vector<int> in_tree;
    in_tree.emplace_back(root);
    vector<int> f(n);
    iota(f.begin(), f.end(), 1);
    shuffle(f.begin(), f.end(), default_random_engine(time(NULL)));
    vector<pair<int, int> > G;
    for(auto x : f){
        if(x == root) continue;
        int fa = in_tree[Rand_int(6) % (int)(in_tree.size())];
        dep[x] = dep[fa] + 1;
        if(dep[x] < 3) in_tree.emplace_back(x);
        G.emplace_back(x, fa);
    }
    shuffle(G.begin(), G.end(), default_random_engine(time(NULL)));
    return G;
}
原文