分治思想 大佬救我
查看原帖
分治思想 大佬救我
590571
_weishiqi66_楼主2023/3/6 13:49
#include<bits/stdc++.h>
using namespace std;
int n;
char s[1025];
void tree (int l,int r){
	int mid=(l+r)/2;
	if(l!=r){
		tree(l,mid);
		tree(mid+1,r);
	}
	bool b=0,i=0;
	for(int k=l;k<=r;k++){
		if(s[k]=='0')b=1;
		if(s[k]=='1')i=1;
	}
	if(b&&i) cout<<"F";
	else {
		if(b)  cout<<"I";
		else cout<<"B";
	}
}
int main(){
	scanf("%d",&n);
	scanf("%s",&s+1);
	tree(1,pow(2,n));
	return 0;
}
2023/3/6 13:49
加载中...