s组t3带特殊性质的数据生成器
  • 板块学术版
  • 楼主zymooll
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/10/23 20:23
  • 上次更新2023/11/2 11:40:33
查看原帖
s组t3带特殊性质的数据生成器
289296
zymooll楼主2023/10/23 20:23

这个版本的可以进行特殊性质的限制。限制方法为改变程序开头的 A,B,C,D 常量的值。

已知的特性:

  • addr 可能超过 101810^{18},尤其是单独使用 D 性质,建议开小 k。

下面是代码:

// Author:zymooll

#include<bits/stdc++.h>

#if defined(__linux__)
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#elif defined(_WIN32)
#define getchar _getchar_nolock
#define putchar _putchar_nolock
#endif

#define int long long
using namespace std;

const int n = 100;
const int k = 100;
const int slen = 10;
const bool A = 0;
const bool B = 0;
const bool C = 0;
const bool D = 0;

int tot1 = 0;//记录 1 操作的总次数
map<string, int>mp;//结构体名称映射
map<string, bool>vis;//标记成员的出现情况

struct S{
  string nam;
  vector<pair<int, string> >mem;
};
vector<S>stru;//记录随机出的

random_device rd;
mt19937_64 mt;

void init(){
  mt.seed(rd());
  stru.push_back((S){ "", vector<pair<int, string> >() });
  stru.push_back((S){ "byte", vector<pair<int, string> >() }); mp["byte"] = 1;
  stru.push_back((S){ "short", vector<pair<int, string> >() }); mp["short"] = 2;
  stru.push_back((S){ "int", vector<pair<int, string> >() }); mp["int"] = 3;
  stru.push_back((S){ "long", vector<pair<int, string> >() }); mp["long"] = 4;
}
int getOperation(){//获取随机的操作
  if(A || (B && tot1)){
    if(stru[0].mem.empty()){//2,4
      int ret = mt() % 2;
      if(ret == 0)ret = 2;
      else ret = 4;
      return ret;//define element
    }
    else{//2,3,4
      return 2 + mt() % 3;
    }
  }
  else if(stru[0].mem.empty()){//1,2,4
    int ret = 1 + mt() % 2;
    if(ret == 3)ret = 4;
    if(ret == 1)tot1++;
    return ret;
  }
  else{//1,2,3,4
    int ret = 1 + mt() % 4;
    if(ret == 1)tot1++;
    return ret;
  }
}
int getType(bool _instru){//获取随机的元素,其中返回值代表结构体 id (_instru 代表是否获取的是结构体内元素)
  if(D)return 4 + mt() % (stru.size() - 4);
  if(C && _instru)return 1 + mt() % 4;
  return 1 + mt() % (stru.size() - 1);
}
string getRamdomString(){//获得一个未出现过的字符串
  string ret;
  for(int i = 0; i < slen; i++){
    ret += 'a' + mt() % 26;
  }
  while(mp[ret] || vis[ret]){
    int pos = mt() % slen;
    ret[pos] = 'a' + mt() % 26;
  }
  return ret;
}

signed main(){
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  init();
  cout << n << endl;
  for(int kk = 1; kk <= n; kk++){
    int opt = getOperation();
    cout << opt << " ";
    // cerr << kk << " " << opt << endl;
    if(opt == 1){
      vis.clear();
      S ls;//临时
      string name = getRamdomString();
      int num = 1 + mt() % k;
      cout << name << " " << num << endl;
      ls.nam = name;
      for(int i = 1; i <= num; i++){
        int type = getType(true);
        string elename = getRamdomString();
        vis[elename] = 1;
        cout << stru[type].nam << " " << elename << endl;
        ls.mem.push_back(make_pair(type, elename));
      }
      stru.push_back(ls);
    }
    else if(opt == 2){
      int type = getType(false);
      string name = getRamdomString();
      stru[0].mem.push_back(make_pair(type, name));
      cout << stru[type].nam << " " << name << endl;
    }
    else if(opt == 3){
      int u = 0;
      string outp = "";
      while(1){
        int pos = mt() % stru[u].mem.size();
        if(u)outp += ".";
        outp += stru[u].mem[pos].second;
        // cerr << " - " << pos << " " << outp << endl;
        if(stru[u].mem[pos].first <= 4){//是基本元素
          break;
        }
        u = stru[u].mem[pos].first;
      }
      cout << outp << endl;
    }
    else{
      cout << mt() % (8 * kk) << endl;
    }
    cout << endl;
  }
  return 0;
}

帮到你麻烦留言关注!谢谢!

2023/10/23 20:23
加载中...