AcWing 419. FBI树
原题链接
简单
作者:
Value
,
2020-09-08 09:27:35
,
所有人可见
,
阅读 388
#include <iostream>
#include <cmath>
using namespace std;
void FBI(string s, int l, int r){
if(l == r){
if(s[l] == '0') cout << 'B';
else cout << 'I';
return ;
}
FBI(s, l, l + r >> 1);
FBI(s, (l + r >> 1) + 1, r);
bool B, I;
B = I = false;
for(int i = l; i <= r; i ++ ){
if(s[i] == '0') B = true;
else I = true;
}
if(B && I) cout << 'F';
else if(B) cout << 'B';
else cout << 'I';
}
int main(){
int n;
string s;
cin >> n >> s;
FBI(s, 0, int(pow(2, n)) - 1);
return 0;
}