求助!!自己跑为什么连输出都没有??
查看原帖
求助!!自己跑为什么连输出都没有??
473188
NaHCO3_tht楼主2021/5/28 18:56
#include <bits/stdc++.h>
#define MAXN 1030
#define ll long long
using namespace std;
typedef struct node;
typedef node* tree;
struct node{
	char data;
	tree lc,rc,fa;
};
tree bt;
char a[MAXN];
int n,m,x = 1,aa[MAXN];
//inline ll pow(ll x,ll y){
//    ll ans=1;
//    while(y){
//        if(y&1){
//            ans=ans*x;
//        }
//        x=x*x;
//        y>>=1;
//    }
//    return ans;
//}
inline void build(tree now){
	while(n--){
		build(now->lc);
		build(now->rc);
	}
	if((!now->lc)&&(!now->rc)){
		now->data = a[x++];
	}else{
		tree l = now->lc;tree r = now->rc;
		if(r->data == l->data){
			now->data = 'F';
		}else{
			now->data = r->data;
		}
	}
}
inline void postorder(tree k){
	if(k){
		postorder(k->lc);
		postorder(k->rc);
		cout<<k->data;
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
//	m = pow(2,n);
	m = 1<<n;
	for(register int i = 1;i <= m;i++){
		int k;
		scanf("%1d",&aa[i]);
	}
	for(register int i = 1;i <= m;i++){
		if(aa[i] == 1){
			a[i] = 'I';
		}else{
			a[i] = 'B';
		}
	}
	build(bt);
	postorder(bt);
	return 0;
}
2021/5/28 18:56
加载中...