提交时间:2023-08-23 16:38:56
运行 ID: 99736
#include <bits/stdc++.h> using namespace std; int a[10086][2]; char typ[10086]; void dfs(int num, string s) { if (s.find('0') == -1) { typ[num] = 'I'; } else if (s.find('1') == -1) { typ[num] = 'B'; } else { typ[num] = 'F'; } if (s.size() != 1) { dfs(num * 2, s.substr(0, s.size() / 2)); dfs(num * 2 + 1, s.substr(s.size() / 2, s.size() / 2)); a[num][0] = num * 2; a[num][1] = num * 2 + 1; } } void shower(int cur) { if (a[cur][0] != 0) { shower(a[cur][0]); shower(a[cur][1]); } cout << typ[cur]; } int main() { // https://www.luogu.com.cn/problem/P1087 int n; string s; cin >> n >> s; dfs(1, s); shower(1); return 0; }