2022/9/11 重拾OI
2023/5/15 100AC,by B3761 三角魔方,亦第一道绿题这你也要记。
2023/7/19 第一道蓝题AC,byP3919 可持久化线段树1这你也要记。
2023/7/24 第一道紫题AC,byP5494 线段树分裂怎么全是模板题啊
2023/9/2 200AC,byP2820 局域网
2023/11/6 300AC,byP4933 大师
2023/11/13 橙名祭
2024/10/9 400AC,byP3017 Brownie Slicing G
2024/10/16 第一道完全独立完成的紫题,byP11189 水杯降温好耶!!!
2024/11/13 100绿题AC,byP4290 玩具取名
2024/11/18 再度橙名
2024/11/30 NOIp2024
2024/12/2 红名祭!
2024/12/23 AFO
玩过一加一吗?
/*
用于生成解答树,输出类型为文件输出,输出文件名为“Ans-Tree.txt”。
使用方法:
输入某个情况下的节点编号和需求的解答子树高度(一般为3就合适),其输出以该节点为根,相应高度的子树。
范例:
输入:1 3
输出:
1 2
1 1
1 2
1 3
2 2 2 4 1 3 1 5
1 3 1 3 1 3 1 3
2 2 2 4 1 3 1 5
1 5 3 3 1 6 1 4
2 3 2 7 2 3 2 7 4 5 4 5 2 7 2 7 2 3 3 7 1 4 1 9 2 5 5 5 1 6 1 9
1 5 1 5 1 5 1 5 3 3 3 3 3 3 3 3 1 6 1 6 1 6 1 6 1 4 1 4 1 4 1 4
2 3 2 7 2 3 2 7 4 5 4 5 2 7 2 7 2 3 3 7 1 4 1 9 2 5 5 5 1 6 1 9
1 8 1 X 1 8 1 X 3 8 3 8 3 X 3 X 1 8 1 X 1 X 1 X 3 4 4 6 1 X 1 X
(3) (32) (40) (69) (78) (89) (100) (106) (113) (142) (149) (159) (165) (196) (207) (218)
其中叶节点下面的括号代表其节点编号,依次可以继续查询。
另外,目前并不支持直接查询除原始状态(指敌方 1 2,我方1 1的状态,是根节点,节点编号为1)之外的状态,除非你清楚它的节点编号。你只能从根节点开始向下寻找,这要求你清楚你们每一步是怎么走的。
*/
#include <iostream>//2023.5.6 18:26 首次计算出后手必胜 //2023.5.6 19:20 制作出后手交互版 //2023.9.24 23:19 制作出可读性优秀的生成解答树版并完成了正确性检验
#include <stdio.h>
#include <vector>
using namespace std;
vector <int> this_v,next_v;
int num[4] = {1,1,1,1},bigcon = 0,step = 1;
string line1,line2,line3,line4,line5;
struct memory{
int b[10][10];
}a[10][10];
bool win(int act)
{
return num[act] >= 10 && num[act + 1] >= 10;
}
int af,as,bf,bs;
void dic(int act)
{
if (num[act] <= num[act + 1])
{
af = num[act];
as = num[act + 1];
}
else
{
af = num[act + 1];
as = num[act];
}
if (num[2 - act] <= num[2 - act + 1])
{
bf = num[2 - act];
bs = num[2 - act + 1];
}
else
{
bf = num[2 - act + 1];
bs = num[2 - act];
}
}
int recall(int act)
{
dic(act);
return a[af][as].b[bf][bs];
}
void write(int act,int k)
{
dic(act);
a[af][as].b[bf][bs] = k;
}
void dfs(int action)
{
if (recall(action) == 1)
{
return;
}
if (recall(action) == -1)
{
bigcon = 1;
return;
}
for (int i = action;i <= action + 1;i++)
{
if (num[i] < 10)
{
for (int j = (2 - action);j <= (2 - action + 1);j++)
{
if (num[j] < 10)
{
num[i] += num[j];
if (win(action))
{
num[i] -= num[j];
return;
}
step++;
dfs(2 - action);
step--;
num[i] -= num[j];
if (bigcon)
{
if (step == 2)
{
bigcon++;
}
bigcon--;
write(action,1);
return;
}
}
}
}
}
bigcon = 1;
write(action,-1);
return;
}
int s1,s2,s3,s4;
void ans()
{
for (int i = 2;i <= 3;i++)
{
if (num[i] < 10)
{
for (int j = 0;j <= 1;j++)
{
if (num[j] < 10)
{
num[i] += num[j];
if (recall(0) == -1)
{
s1 = min(num[0],num[1]),s2 = max(num[0],num[1]),s3 = min(num[2],num[3]),s4 = max(num[2],num[3]);
return;
}
num[i] -= num[j];
}
}
}
}
s1 = 10,s2 = 10,s3 = 10,s4 = 10;
return;
}
struct Ans_Tree{
int son[4];
int situ[4];
int solve[4];
}ans_tree[20 * 20 * 20 *20];
int pos = 1;
void make_tree(int now,int n1,int n2,int n3,int n4)
{
ans_tree[now].situ[0] = num[0] = n1,ans_tree[now].situ[1] = num[1] = n2,ans_tree[now].situ[2] = num[2] = n3,ans_tree[now].situ[3] = num[3] = n4;
ans();
ans_tree[now].solve[0] = s1,ans_tree[now].solve[1] = s2,ans_tree[now].solve[2] = s3,ans_tree[now].solve[3] = s4;
int sons = 0;
for (int i = 0;i <= 1;i++)
{
if (ans_tree[now].solve[i] < 10)
{
for (int j = 2;j <= 3;j++)
{
if (ans_tree[now].solve[j] < 10)
{
ans_tree[now].solve[i] += ans_tree[now].solve[j];
ans_tree[now].son[sons++] = ++pos;
make_tree(pos,min(ans_tree[now].solve[0],ans_tree[now].solve[1]),max(ans_tree[now].solve[0],ans_tree[now].solve[1]),min(ans_tree[now].solve[2],ans_tree[now].solve[3]),max(ans_tree[now].solve[2],ans_tree[now].solve[3]));
ans_tree[now].solve[i] -= ans_tree[now].solve[j];
}
}
}
}
}
string str(int num)
{
string ans,ap;
int rest=num;
if (num == 0)
{
return "0";
}
while (rest>0)
{
ap=(rest%10)+'0';
ans.insert(0,ap);
rest/=10;
}
return ans;
}//读入一个int,返还其string类型
void cout_subtree(int root,int k)
{
this_v.push_back(root);
while (this_v.empty() == 0 && k--)
{
line5 = "";
for (int it : this_v)
{
line1 = line1 + (ans_tree[it].situ[0] >= 10 ? 'X' : (char)(ans_tree[it].situ[0] + '0')) + " " + (ans_tree[it].situ[1] >= 10 ? 'X' : (char)(ans_tree[it].situ[1] + '0')) + " ";
line2 = line2 + (ans_tree[it].situ[2] >= 10 ? 'X' : (char)(ans_tree[it].situ[2] + '0')) + " " + (ans_tree[it].situ[3] >= 10 ? 'X' : (char)(ans_tree[it].situ[3] + '0')) + " ";
line3 = line1;
line4 = line4 + (ans_tree[it].solve[2] >= 10 ? 'X' : (char)(ans_tree[it].solve[2] + '0')) + " " + (ans_tree[it].solve[3] >= 10 ? 'X' : (char)(ans_tree[it].solve[3] + '0')) + " ";
line5 = line5 + "(" + str(it) + ")";
for (int j = 1;j <= (int)(7 - str(it).length());j++)
{
line5 = line5 + " ";
}
int zhi = 0;
while (ans_tree[it].son[zhi] != 0 && zhi < 4)
{
next_v.push_back(ans_tree[it].son[zhi]);
zhi++;
}
}
cout << line1 << "\n" << line2 << "\n" << line3 << "\n" << line4 << "\n\n";
line1 = line2 = line3 = line4 = "";
swap(this_v,next_v);
vector <int> emp;
swap(next_v,emp);
}
cout << line5 << "\n\n";
line5 = "";
vector <int> emp;
swap(this_v,emp);
}
int main()
{
freopen("Ans-Tree.txt","w",stdout);
dfs(0);
make_tree(1,1,2,1,1);
int ask,depth;
scanf("%d %d",&ask,&depth);
cout_subtree(ask,depth);
return 0;
}