分辨率树题解(doge)

凌艺樽  •  12天前


#include <bits/stdc++.h>
using namespace std;
const int N=1e4+10;
string tr[20],s;
int n,a[N],p;
int main()
{
	cin>>n>>s;
	for(int i=0;i<s.size();++i)
	{
		cout<<(s[i]=='0'?'B':'I');
		if(s[i]=='0')tr[0]+="B";
		if(s[i]=='1')tr[0]+="I";
		for(int j=0;j<=n;++j)
		{
			if(tr[j].size()>=2)
			{
				if(tr[j][0]==tr[j][1] && tr[j][0]!='F')tr[j+1]+=tr[j][0];
				else tr[j+1]+="F";
				cout<<tr[j+1][tr[j+1].size()-1];
				if(j+1==n)return 0;
				tr[j]="";
			}
			else
			{
				break;
			}
		}
	}
	return 0;
}

评论: