因为某些暂时不知道原因的bug,有时候的它生成的数据有点问题,不太能用,不过出现这种情况的概率不高,大部分情况都还是很好用的
#include <bits/stdc++.h>
#define Code using
#define by namespace
#define wjb std
Code by wjb;
#define int long long
bool randomNumCount = 1; // 这个不可更改
int numMaxCount = 20;
// 可接受范围:2 ~ 300000000,表示生成的最大数字个数
int numMaxLength = 1;
// 可接受范围:1 ~ 9,但是大于 9 也行。表示一个数字最大位数,填进去 2147483647 恶心做题人也不是不可以
const int H = 110, W = 9100;
const double PI = acos(-1.0);
string standard[20][H] = {
{
"...........########...........",
".........############.........",
".......################.......",
"......##################......",
".....####################.....",
"....######################....",
"...########################...",
"...##########....##########...",
"..#########........#########..",
"..########..........########..",
".#########..........#########.",
".########............########.",
".########............########.",
".########............########.",
"########..............########",
"########..............########",
"########..............########",
"########..............########",
"########..............########",
"########..............########",
"########..............########",
"########..............########",
"########..............########",
"########..............########",
"########..............########",
".########............########.",
".########............########.",
".########............########.",
".#########..........#########.",
"..########..........########..",
"..#########........#########..",
"...##########....##########...",
"...########################...",
"....######################....",
".....####################.....",
"......##################......",
".......################.......",
".........############.........",
"...........########...........",
},
{
".............####..........",
"...........#######.........",
"........##########.........",
".....#############.........",
"..################.........",
".#################.........",
".#################.........",
".#################.........",
".#################.........",
"..######..########.........",
"..###.....########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
"..........########.........",
".##########################",
"###########################",
"###########################",
"###########################",
"###########################",
".##########################",
},
{
".........#########..........",
"......##############........",
"...###################......",
"..#####################.....",
".#######################....",
".#######################....",
".########################...",
".#########......#########...",
".#######.........#########..",
".#######..........########..",
".#######..........########..",
".#######..........########..",
".#######..........########..",
"..######..........########..",
".................#########..",
".................########...",
"................#########...",
"...............##########...",
"..............##########....",
".............###########....",
"............###########.....",
"...........###########......",
"..........###########.......",
".........###########........",
"........###########.........",
".......###########..........",
"......###########.....#####.",
".....###########.....#######",
"....###########......#######",
"...###########.......#######",
"..###########........#######",
".###########.........#######",
"############################",
"############################",
"############################",
"############################",
"############################",
".###########################",
},
{
".........##########.........",
".....################.......",
"...####################.....",
"..######################....",
"..#######################...",
"..########################..",
"..########################..",
"..########.......##########.",
"..#######.........#########.",
"..#######..........########.",
"..#######..........########.",
"...######..........########.",
"...................########.",
"...................########.",
"..................########..",
".................#########..",
"..........###############...",
".........###############....",
".........##############.....",
".........###############....",
".........################...",
"..........################..",
".................##########.",
"...................########.",
"...................#########",
"....................########",
"....................########",
"....................########",
"....................########",
"...................#########",
"..###.............##########",
".########........##########.",
".##########################.",
".#########################..",
"##########################..",
".########################...",
".######################.....",
"....#################.......",
".......###########..........",
},
{
".................#####........",
"................#######.......",
"...............########.......",
"..............#########.......",
".............##########.......",
"............###########.......",
"............###########.......",
"...........############.......",
"..........#############.......",
".........##############.......",
"........###############.......",
".......################.......",
".......########.#######.......",
"......########..#######.......",
".....########...#######.......",
"....########....#######.......",
"...#########....#######.......",
"...########.....#######.......",
"..########......#######.......",
".########.......#######.......",
"##############################",
"##############################",
"##############################",
"##############################",
"##############################",
"##############################",
"...............########.......",
"...............########.......",
"...............########.......",
"...............########.......",
"...............########.......",
"...............########.......",
".........####################.",
"........#####################.",
"........#####################.",
"........#####################.",
"........#####################.",
".........####################.",
},
{
"...######################...",
"...#######################..",
"...#######################..",
"...#######################..",
"...#######################..",
"...######################...",
"...#######..................",
"...#######..................",
"...#######..................",
"...#######..................",
"...#######..................",
"...#######..................",
"..########..########........",
"..####################......",
"..######################....",
"..#######################...",
"..########################..",
"..########################..",
"..#########################.",
"..########.......##########.",
".....##...........#########.",
"...................#########",
"....................########",
"....................########",
"....................########",
"....................########",
"....................########",
"....................########",
"...#...............#########",
"..####............#########.",
".########.......###########.",
".##########################.",
".#########################..",
"#########################...",
".#######################....",
"..#####################.....",
"....#################.......",
"........##########..........",
},
{
"....................######...",
"...............###########...",
"............###############..",
"..........#################..",
"........###################..",
".......####################..",
"......####################...",
".....################........",
"....############.............",
"...###########...............",
"...#########.................",
"..#########..................",
"..########...................",
".########....................",
".########....................",
".#######....########.........",
".#######..#############......",
"#########################....",
"##########################...",
"###########################..",
"###########################..",
"############......##########.",
"##########.........#########.",
"#########...........#########",
"########.............########",
"########.............########",
"########.............########",
".#######.............########",
".#######.............########",
".########...........#########",
".#########.........#########.",
"..##########.....###########.",
"...#########################.",
"...########################..",
"....######################...",
".....####################....",
"......##################.....",
"........##############.......",
"...........########..........",
},
{
"###########################.",
"############################",
"############################",
"############################",
"############################",
"###########################.",
"#######...........#########.",
"#######...........#########.",
"#######..........#########..",
"#######..........#########..",
"#######..........########...",
"#######.........#########...",
"#######.........########....",
"#######........#########....",
".#####.........#########....",
"...............########.....",
"..............#########.....",
"..............########......",
".............#########......",
".............########.......",
"............#########.......",
"............#########.......",
"............########........",
"...........#########........",
"...........########.........",
"..........#########.........",
"..........########..........",
"..........########..........",
".........########...........",
".........########...........",
"........#########...........",
"........########............",
"........########............",
".......########.............",
".......########.............",
".......#######..............",
".......#######..............",
".........#####..............",
},
{
"..........#########.........",
"........#############.......",
"......#################.....",
".....###################....",
"....#####################...",
"...#######################..",
"...#######################..",
"...#########.....#########..",
"..#########.......#########.",
"..########.........########.",
"..########.........########.",
"..########.........########.",
"..########.........########.",
"..########.........########.",
"...########.......########..",
"...#########.....#########..",
"....#####################...",
".....###################....",
"......#################.....",
"......#################.....",
"....#####################...",
"...#######################..",
"..#########......##########.",
".########..........########.",
".########..........#########",
"########............########",
"########............########",
"########............########",
"########............########",
"#########..........#########",
"#########..........#########",
".##########......##########.",
".##########################.",
"..########################..",
"..########################..",
"...######################...",
"....####################....",
"......################......",
".........##########.........",
},
{
".........#########..........",
".......#############........",
".....#################......",
"....###################.....",
"...#####################....",
"..#######################...",
".########################...",
".##########......#########..",
".#########........#########.",
"#########..........########.",
"########............#######.",
"########............#######.",
"########............########",
"########............########",
"########............########",
"#########..........#########",
".########.........##########",
".##########......###########",
"..##########################",
"..##########################",
"...#########################",
"....########################",
"......############..########",
"........########....#######.",
"....................#######.",
"...................########.",
"...................########.",
"..................########..",
".................#########..",
"...............##########...",
".............############...",
".........###############....",
"....###################.....",
"...###################......",
"...##################.......",
"...################.........",
"...##############...........",
"...############.............",
"....######..................",
},
{
"...............####..",
"..............######.",
"............########.",
"...........##########",
"..........###########",
".........############",
"........############.",
".......###########...",
"......###########....",
".....###########.....",
".....##########......",
"....##########.......",
"....#########........",
"...#########.........",
"...########..........",
"..#########..........",
"..########...........",
".#########...........",
".########............",
".########............",
".########............",
"#########............",
"########.............",
"########.............",
"########.............",
"########.............",
"########.............",
"########.............",
"########.............",
"########.............",
"########.............",
"########.............",
".########............",
".########............",
".########............",
".#########...........",
"..########...........",
"..#########..........",
"..#########..........",
"...#########.........",
"...##########........",
"....#########........",
".....#########.......",
".....##########......",
"......###########....",
".......###########...",
"........###########..",
".........############",
"..........###########",
"...........##########",
"............#########",
".............#######.",
"...............####..",
".................#...",
},
{
"..####...............",
".######..............",
"#########............",
"##########...........",
"###########..........",
"############.........",
".############........",
"...###########.......",
"....###########......",
".....##########......",
"......##########.....",
".......##########....",
"........#########....",
".........#########...",
"..........########...",
"..........#########..",
"...........########..",
"...........#########.",
"............########.",
"............########.",
"............########.",
"............#########",
".............########",
".............########",
".............########",
".............########",
".............########",
".............########",
".............########",
".............########",
".............########",
".............########",
"............########.",
"............########.",
"............########.",
"...........#########.",
"...........########..",
"..........#########..",
"..........#########..",
".........#########...",
"........##########...",
".......##########....",
".......#########.....",
".....###########.....",
"....###########......",
"...###########.......",
"..###########........",
"############.........",
"###########..........",
"##########...........",
"#########............",
".#######.............",
"..####...............",
"...#.................",
},
{
"...........#####...........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"###########################",
"###########################",
"###########################",
"###########################",
"###########################",
"###########################",
"###########################",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"..........#######..........",
"...........#####...........",
},
{
".##########################.",
"############################",
"############################",
"############################",
"############################",
"############################",
".###########################",
},
{
"...........####...........",
"..........######..........",
"..........#######.........",
".........########.........",
".........########.........",
"..........#######.........",
"..........######..........",
".#####....######.....####.",
".######...######...#######",
"#########..#####.#########",
"###############.##########",
"##########################",
"##########################",
".########################.",
"......##############......",
".........########.........",
"........###########.......",
".......#############......",
".....########.#######.....",
"....########..########....",
"....########..#########...",
"...########....########...",
"...########....########...",
"....#######.....#######...",
".....#####......######....",
"......###.........##......",
},
{
"......................####..",
"......................######",
".....................#######",
".....................#######",
"....................########",
"....................#######.",
"...................########.",
"...................#######..",
"..................########..",
"..................#######...",
".................########...",
".................#######....",
"................########....",
"................########....",
"................#######.....",
"...............########.....",
"...............#######......",
"..............########......",
"..............#######.......",
".............########.......",
".............#######........",
"............########........",
"............#######.........",
"...........########.........",
"...........#######..........",
"..........########..........",
"..........#######...........",
"..........#######...........",
".........########...........",
".........#######............",
"........########............",
"........#######.............",
".......########.............",
".......#######..............",
"......########..............",
"......#######...............",
".....########...............",
".....#######................",
"....########................",
"....#######.................",
"...########.................",
"...########.................",
"...#######..................",
"..########..................",
"..#######...................",
".########...................",
".#######....................",
"########....................",
"#######.....................",
".######.....................",
"..#####.....................",
}};
double random(double l, double r)
{
random_device rd;
mt19937 gen(rd());
uniform_real_distribution<> dis(l, r);
return dis(gen);
} // 生成随机数
struct notation // 单个字符
{
int ch[H];
void ass(int i, int j, char k)
{
if (k == '#')
ch[i] |= (1ll << j);
else
ch[i] &= (~(1ll << j));
}
char ext(int i, int j) { return ((ch[i] >> j) & 1ll) ? '#' : '.'; }
int h, w;
notation() { h = w = 0, memset(ch, 0, sizeof(ch)); }
};
vector<notation> nota;
auto find_center(notation &t) // 找中心
{
int x = 0, y = 0, cnt = 0;
for (int i = 1; i <= t.h; i++)
for (int j = 1; j <= t.w; j++)
if (t.ext(i, j) == '#')
x += i, y += j, cnt++;
return make_pair(round(double(x) / cnt), round(double(y) / cnt));
}
void move_to_the_center(notation &origin) // 将图像居中
{
pair<int, int> tmpcenter = find_center(origin), center = make_pair(33, 19);
notation a;
for (int i = 0; i <= 66; i++)
for (int j = 0; j <= 39; j++)
a.ass(i, j, '.');
for (int i = 1; i <= origin.h; i++)
for (int j = 1; j <= origin.w; j++)
if (origin.ext(i, j) == '#')
{
int nx = center.first - tmpcenter.first + i, ny = center.second - tmpcenter.second + j;
if (nx < 1 || nx > 65 || ny < 1 || ny > 38)
continue;
a.ass(nx, ny, '#');
}
origin = a, origin.h = 65, origin.w = 38;
}
void create(notation &origin) // 生成字符
{
auto rotate = [&](notation &t, double angle) // 逆时针旋转 angle 度
{
notation tmp;
auto center = make_pair(33, 19);
tmp.h = t.h, tmp.w = t.w;
for (int i = 0; i <= tmp.h + 1; i++)
for (int j = 0; j <= tmp.w + 1; j++)
tmp.ass(i, j, '.');
angle = angle * PI / 180.0;
for (int i = 1; i <= t.h; i++)
for (int j = 1; j <= t.w; j++)
if (t.ext(i, j) == '#')
{
int nx = round(double(i - center.first) * cos(angle) - double(j - center.second) * sin(angle) + center.first);
int ny = round(double(i - center.first) * sin(angle) + double(j - center.second) * cos(angle) + center.second);
if (nx < 1 || nx > tmp.h || ny < 1 || ny > tmp.w)
continue;
tmp.ass(nx, ny, '#');
}
return tmp;
};
auto shrink = [&](notation &t, double rate, bool lateral, bool longitudinal) // 缩小 rate 率,横纵坐标分别缩不缩小
{
notation tmp;
auto center = make_pair(33, 19);
tmp.h = t.h, tmp.w = t.w;
for (int i = 0; i <= tmp.h + 1; i++)
for (int j = 0; j <= tmp.w + 1; j++)
tmp.ass(i, j, '.');
for (int i = 1; i <= t.h; i++)
for (int j = 1; j <= t.w; j++)
if (t.ext(i, j) == '#')
{
int nx = round(double(i - center.first) * rate + center.first), ny = round(double(j - center.second) * rate + center.second);
if (!lateral)
nx = i;
if (!longitudinal)
ny = j;
if (nx < 1 || nx > tmp.h || ny < 1 || ny > tmp.w)
continue;
tmp.ass(nx, ny, '#');
}
return tmp;
};
auto distort = [&](notation &t, double par1, double par2) // 扭曲使其失真,参数 1 2
{
notation tmp;
tmp.h = t.h, tmp.w = t.w;
for (int i = 0; i <= tmp.h + 1; i++)
for (int j = 0; j <= tmp.w + 1; j++)
tmp.ass(i, j, '.');
for (int i = 1; i <= t.h; i++)
for (int j = 1; j <= t.w; j++)
if (t.ext(i, j) == '#')
{
int nx = i + par2 * j, ny = par1 * i + j;
if (nx < 1 || nx > tmp.h || ny < 1 || ny > tmp.w)
continue;
tmp.ass(nx, ny, '#');
}
return tmp;
};
double angle = round(random(-15, 15)), rate = random(0.9, 1), par1 = random(-0.1, 0.1), par2 = random(-0.1, 0.1);
int lateral = round(random(0, 1)), longitudinal = round(random(0, 1));
origin = shrink(origin, rate, lateral, longitudinal), origin = rotate(origin, angle), origin = distort(origin, par1, par2);
move_to_the_center(origin);
}
notation rnd[11000];
string s = "0123456789()+-*/";
void init(string a) // 预处理随机字符
{
auto trans = [&](string s[])
{
notation res;
int i;
for (i = 1; i == 1 || (s[i - 1].size() == s[i - 2].size()); i++)
for (int j = 1; j <= s[i - 1].size(); j++)
res.ass(i, j, s[i - 1][j - 1]);
res.h = i - 1, res.w = s[0].size(), move_to_the_center(res);
return res;
};
int w = 0;
for (int task = 1; task <= a.size(); task++)
rnd[task] = trans(standard[s.find(a[task - 1])]), create(rnd[task]), w += rnd[task].w;
cout << "135\n"
<< w + a.size() * 10 << " 65\n";
for (int i = 1; i <= 65; cout << "\n", i++)
for (int task = 1; task <= a.size(); task++)
{
for (int j = 1; j <= rnd[task].w; j++)
if (rand() % 20 != 10)
cout << rnd[task].ext(i, j);
else if (rnd[task].ext(i, j) == '#')
cout << ".";
else
cout << "#";
for (int j = 1; j <= 10; j++)
if (rand() % 20 == 10)
cout << "#";
else
cout << ".";
}
}
int pr[129]; // 运算优先级表
void init()
{
// operators priority
// + == - <= * == / <= ^ <= ...... < ()
// pr[(char)] -> pr[(ASCII)]
pr['+'] = 1;
pr['-'] = 1;
pr['*'] = 2;
pr['/'] = 2;
}
queue<string> randsuffix()
{ // 随机生成后缀表达式
queue<string> ret;
string s;
int r;
if (randomNumCount)
{
numMaxCount -= 1;
if (numMaxCount <= 0)
numMaxCount = 1;
r = 2 + (((rand() * 10000) + rand()) % numMaxCount);
// rand 范围为 0 ~ 32767
// 所以理论上随机最大可以生成 327702768
}
else
{
if (numMaxCount <= 1)
numMaxCount = 2;
r = numMaxCount;
}
numMaxLength = max(numMaxLength, 1ll);
int ops = 0;
for (int i = 1; i <= r; i++)
{
// 生成数字
int dg = 1 + (rand() % numMaxLength);
bool tit = 1;
s = "";
while (dg--)
{
if (tit == 1)
{ // 避免前导 0
s += char(49 + (rand() % 9));
tit = 0;
}
else
{
s += char(48 + (rand() % 10));
}
}
ret.push(s);
s = "";
// 随机生成符号
if (ops < 2 * i / 3 && (rand() % 3) == 0)
{
int op = (rand() % 4);
if (op == 0)
s += "+";
if (op == 1)
s += "-";
if (op == 2)
s += "*";
if (op == 3)
s += "/";
ret.push(s);
s = "";
ops++;
}
}
// 最后补齐符号
for (; ops < r - 1; ops++)
{
int op = (rand() % 4);
if (op == 0)
s += "+";
if (op == 1)
s += "-";
if (op == 2)
s += "*";
if (op == 3)
s += "/";
ret.push(s);
s = "";
}
return ret;
}
#define psi pair<string, int>
#define str first
#define pri second
#define mp make_pair
signed main()
{
freopen("in.txt", "w", stdout);
init();
srand((unsigned)time(NULL));
queue<string> q = randsuffix();
stack<psi> s;
// int sz = q.size ();
// cout << "There are " << sz;
// cout << " elements in the queue:\n";
/* // 输出后缀表达式
for (int i = 1; i <= sz; i++) {
string s = q.front ();
q.pop ();
cout << s << " ";
q.push (s);
}
cout << endl;*/
while (!q.empty())
{
// cout << q.size () << endl;
psi tmp;
tmp.str = q.front();
q.pop();
if (!isdigit(tmp.str[0]))
{
tmp.pri = pr[tmp.str[0]];
psi t2 = s.top();
s.pop();
psi t1 = s.top();
s.pop();
psi ret;
if (t1.pri < tmp.pri)
{ // 判断前面需不需要加括号
ret.str += "(" + t1.str + ")";
}
else
{
ret.str += t1.str;
}
ret.str += tmp.str;
if (t2.pri < tmp.pri || // 判断后面需不需要加括号
(tmp.str == "/" && t2.pri <= tmp.pri) || // 特判除法
(tmp.str == "-" && t2.pri <= tmp.pri))
{ // 特判减法
ret.str += "(" + t2.str + ")";
}
else
{
ret.str += t2.str;
}
ret.pri = tmp.pri; // 更新运算优先级
s.push(ret);
}
else
{
tmp.pri = 9999999; // 数字的运算优先级是最大的
s.push(tmp);
}
}
psi ans = s.top();
init(ans.str);
}