/* *\
FBI树
提交两次
第一次弄错范围。是2^10,以为是10
第二次AC
建树三个参数,树的根节点,
对应的字符串范围
一开始纠结如何确定根节点,
后来看了题解突然发现根节点
是一个参数
\* */
#include <cmath>
#include <iostream>
using std::cout;
using std::cin;
long n;
char str[1048];
char tree[1048];
void build(long s,long l,long r)
{
if (l>r) return;
if (l==r)
{
tree[s]=(str[l]=='1'?'I':'B');
cout << tree[s];
return;
}
long m = (l+r)>>1;
build(s*2,l,m);
build(s*2+1,m+1,r);
if (tree[s*2]=='I'&&tree[s*2+1]=='I')
tree[s] = 'I';
else if (tree[s*2]=='B'&&tree[s*2+1]=='B')
tree[s] = 'B';
else tree[s] = 'F';
cout << tree[s];
}
int main()
{
cin >> n >> str+1;
n = 1 << n;
build(1,1,n);
}
【FBI树】解题报告
最新推荐文章于 2024-08-20 11:35:37 发布