跳到正文

个人记录

随机探索派遣生成器

KaguyaH约 10 分钟
原文
文章信息与版本

文章信息

发布
2023年12月22日
收录
2025年12月12日
更新
2026年11月3日
篇幅
约 10 分钟
获赞
2

版本

  1. v1当前

gen.cpp

C++
# include <bits/stdc++.h>

using namespace std;

namespace kh {
  void main(int argc, char* argv[]) {
    // chr : characters
    // min : mines
    // nat : nations
    // plc : places
    // tal : talents
    int const limit(5);
    ifstream cin("data.txt");
    auto const getline = [&cin] {
      string line;
      std::getline(cin, line);
      return line;
    };
    vector<string> chr;
    vector<pair<string, string>> plc;
    vector<pair<string, string>> tal;
    vector<string> min;
    string cur_nat;
    while (true) {
      string line(getline());
      if (line == "end chr") break;
      else chr.emplace_back(line);
    }
    while (true) {
      string line(getline());
      if (line == "end plc") break;
      if (line.substr(0, 3) == "nat")
        cur_nat = line.substr(4);
      else
        plc.emplace_back(cur_nat, line);
    }
    while (true) {
      string line(getline());
      if (line == "end tal") break;
      else tal.emplace_back(line, getline());
    }
    while (true) {
      string line(getline());
      if (line == "end min") break;
      else min.emplace_back(line);
    }
    auto const gen = [chr, plc, tal, min] (int seed) {
      default_random_engine rng(seed);
      bernoulli_distribution rand_bool;
      uniform_int_distribution rnd_chr(0, int(chr.size()) - 1);
      uniform_int_distribution rnd_plc(0, int(plc.size()) - 1);
      vector<int> active(tal.size());
      while (true) {
        for (int& v : active) v = rand_bool(rng);
        if (accumulate(active.begin(), active.end(), 0) <= limit) break;
      }
      while (true) {
        vector<tuple<string, string, string>> dsp;
        for (int i(0); i != int(tal.size()); ++i)
          if (active.at(i)) while (true) {
            auto const& [natp, plcp](plc.at(rnd_plc(rng)));
            auto const& [chrt, natt](tal.at(i));
            if (natp == natt) {
              dsp.emplace_back(natt, plcp, chrt);
              break;
            }
          }
        while (int(dsp.size()) != limit) {
          auto const& rndp(plc.at(rnd_plc(rng)));
          auto const& rndc(chr.at(rnd_chr(rng)));
          dsp.emplace_back(tuple_cat(rndp, tuple(rndc)));
        }
        shuffle(dsp.begin(), dsp.end(), rng);
        bool legal(true), ctn_min(false);
        for (auto const& [nat0, plc0, chr0] : dsp)
          for (auto const& [nat1, plc1, chr1] : dsp) {
            legal = legal && (&plc0 == &plc1 || plc0 != plc1);
            legal = legal && (&chr0 == &chr1 || chr0 != chr1);
          }
        for (auto const& [nat, plc, chr] : dsp) {
          auto const fnd(find(min.begin(), min.end(), plc));
          ctn_min = ctn_min || fnd != min.end();
        }
        if (legal && ctn_min) return dsp;
      }
    };
    vector<tuple<string, string, string>> dsp;
    switch (argc) {
      case 1: dsp = gen(random_device()()); break;
      case 2: dsp = gen(atoi(argv[1])); break;
    }
    int wnat(0), wplc(0), wchr(0);
    for (auto const& [nat, plc, chr] : dsp) {
      wnat = max(wnat, int(nat.length()));
      wplc = max(wplc, int(plc.length()));
      wchr = max(wchr, int(chr.length()));
    }
    for (auto const& [nat, plc, chr] : dsp) {
      cout << setw(wnat) << nat << " | ";
      cout << setw(wplc) << plc << " | ";
      cout << setw(wchr) << chr << endl;
    }
  }
}

int main(int argc, char* argv[]) { kh::main(argc, argv); }

data.txt

代码
Furina
Charlotte
Lynette
Faruzan
Layla
Candace
Collei
Sayu
Yanfei
Rosaria
Hu Tao
Diona
Keqing
Noelle
Fischl
Beidou
Xiangling
Barbara
Lisa
Amber
end chr
nat Mondstadt
Dadaupa Gorge
Stormbearer Montains
Stormterror's Lair
Whispering Woods
Windrise
Wolvendom
nat Liyue
Dihua Marsh
Dunyu Ruins
Guili Plains
Guyun Stone Forest
Jueyun Karst
Yaoguang Shoal
nat Inazuma
Byakko Plain
Jinren Island
Konda Village
Musoujin Gorge
Nazuchi Beach
Tatarasuna
nat Sumeru
Ardravi Valley
Ashavan Realm
Avidya Forest
Chatrakam Cave
Chinvat Ravine
Mawtiyima Forest
nat Fontaine
Beryl Mountains
Elynas Ridge
Erinnyes
Mont Esus
Salacia Plain
The Outskirts of Poisson
end plc
Keqing
Liyue
Fischl
Mondstadt
Faruzan
Sumeru
end tal
Dadaupa Gorge
Whispering Woods
Yaoguang Shoal
end min

可能的输出

代码
Mondstadt | Stormterror's Lair |  Yanfei
   Sumeru |     Ardravi Valley | Faruzan
    Liyue |        Dihua Marsh |  Keqing
Mondstadt |      Dadaupa Gorge | Rosaria
  Inazuma |     Musoujin Gorge | Candace
代码
    Liyue |       Yaoguang Shoal |  Keqing
Mondstadt |   Stormterror's Lair |  Yanfei
Mondstadt |        Dadaupa Gorge |    Sayu
Mondstadt | Stormbearer Montains |  Fischl
   Sumeru |        Avidya Forest | Faruzan
代码
  Sumeru |   Ashavan Realm |  Diona
   Liyue |  Yaoguang Shoal | Fischl
Fontaine | Beryl Mountains |   Lisa
Fontaine |       Mont Esus | Furina
 Inazuma |  Musoujin Gorge | Beidou
原文
存档评论10 条抓取于