【数据结构】[NOIP2004]FBI树

前端之家收集整理的这篇文章主要介绍了【数据结构】[NOIP2004]FBI树前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

题目

就是感觉很像线段树那样建树 然后统计01就行了

代码如下

#include<iostream> #include<cstdio> #include<cctype> using namespace std; #define in = read() typedef long long ll; typedef unsigned int ui; const ll size = 1000 + 100; int n; int num0,num1,mid,ans; char s[size]; inline ll read(){ ll num = 0,f = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)){ num = num*10 + ch - '0'; ch = getchar(); } return num*f; } int pow(int a,int b){ ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b >>= 1; } return ans; } void build(int l,int r){ mid = ((l + r)>>1); if(l != r){ build(l,mid); build(mid + 1,r); } for(register int i=l;i<=r;i++){ if(s[i] == '0') num0 ++; if(s[i] == '1') num1 ++; } if(num0 && num1) printf("F"); else if(!num1) printf("B"); else if(!num0) printf("I"); num0 = 0; num1 = 0; } int main(){ // freopen("fbi.in","r",stdin); // freopen("fbi.out","w",stdout); n in; scanf("%s",s + 1); build(1,pow(2,n)); return 0; } //COYG 
原文链接:https://www.f2er.com/datastructure/382267.html

猜你在找的数据结构相关文章