求助样例过了,只有20分
查看原帖
求助样例过了,只有20分
238203
跟你沟通楼主2020/10/24 18:43
#include<bits/stdc++.h>
using namespace std;
int k, n,len;
char tree[20000],s[200000];
void make(int index)
{
	for (; index > 0; --index)
	{
		if (tree[index * 2] == 'I' && tree[index * 2 + 1] == 'I') tree[index] = 'I';
		else if (tree[index * 2] == 'B' && tree[index * 2 + 1] == 'B') tree[index] = 'B';
		else tree[index] = 'F';
	}
}
char judge(int x)
{
	if (s[x] == '0') return 'B';
	return 'I';
}
void print(int i)
{
	if (i > n) return;
	print(i * 2);
	print(i * 2 + 1);
	cout << tree[i];
}
int main()
{
	cin>>k;while(getchar()!='\n');
	scanf("%s",s);
	n = (int)pow(2, k + 1) - 1;
	len = (int)pow(2, k);
	for (int i = 1; i <= len+1; i += 2)
	{
		tree[(k + i / 2 + 1) * 2] = judge(i-1);
		if(i!=len+1)tree[(k + i / 2 + 1) * 2 + 1] = judge(i);
	}
	make(n / 2);
	print(1);
}
2020/10/24 18:43
加载中...