#include <bits/stdc++.h>
#define lson l, mid, rt * 2 + 1
#define rson mid + 1, r, rt * 2 + 2
using namespace std;
typedef long long ll;
const int N = 11;
int n;
string str;
char a[1 << N];
int pd(int l, int r){//判断是B还是I还是F
int flag1 = 0, flag2 = 0;
for(int i = l; i <= r; i ++){
if(str[i] == '0') flag1 = 1;
if(str[i] == '1') flag2 = 1;
}
if(flag1 == 1 && flag2 == 0) return 1;
else if(flag1 == 0 && flag2 == 1) return 2;
else if(flag1 == 1 && flag2 == 1) return 3;
}
void build(int l, int r, int rt){
if(l == r){
if(str[l] == '0') a[rt] = 'B';
else if(str[l] == '1') a[rt] = 'I';
return;
}
else{
if(pd(l,r) == 1) a[rt] = 'B';
else if(pd(l,r) == 2) a[rt] = 'I';
else if(pd(l,r) == 3) a[rt] = 'F';
int mid = (l + r) >> 1;
build(lson);
build(rson);
}
}
void print(int t){
if(t > (2 *((1 << n) - 1))){
return;
}
print(t * 2 + 1);
print(t * 2 + 2);
cout << a[t];
}
int main() {
cin >> n >> str;
build(0,(1<<n)-1,0);
print(0);
return 0;
}
洛谷P1087 FBI树
最新推荐文章于 2023-05-29 18:19:51 发布