zoukankan      html  css  js  c++  java
  • 【NOIP2004】【Luogu1087】FBI树

    problem

    solution

    codes

    #include<stdio.h>
    #define maxn 1<<12
    using namespace std;
    struct node{
        char t;
        int l, r;
        node():t('*'),l(0),r(0){}
    }tree[maxn];
    char s[maxn];
    int top = -1;
    char check(int le, int ri){
        int l=0, b=0;
        for(int i = le; i <= ri; i++){
            if(s[i]=='1')l=1;
            if(s[i]=='0')b=1;
        }
        if(l==1&&b==1)return 'F';
        if(l)return 'I';
        if(b)return 'B';
    }
    int build(int l, int r){
        if(l >= r){
            tree[++top].t = check(l,r);
            return top;
        }
        tree[++top].t = check(l,r);
        int now = top;
        int root = (l+r)/2;
        tree[now].l = build(l,root);
        tree[now].r = build(root+1,r);
        //printf("root:%d  top:%d
    ",root,top+1);
        //printf("now:%d  lch:%d  rch:%d
    ",now, tree[now].l,tree[now].r);
        return now;
    }
    void dfs(int root){
        //printf("root:%d %d %d
    ",root,tree[root].l,tree[root].r);
        if(tree[root].l)dfs(tree[root].l);
        if(tree[root].r)dfs(tree[root].r);
        printf("%c",tree[root].t);
    }
    int main(){
        //freopen("data.in","r",stdin);
        int n;  scanf("%d%s",&n,s+1);
        n = 1<<n;
        build(1,n);
        dfs(0);
        return 0;
    }
  • 相关阅读:
    BZOJ1087=Codevs2451=洛谷P1896&P2326互不侵犯
    poj1286
    P1066 2^k进制数
    开车旅行
    洛谷P1396 营救
    poj1840
    poj3693
    poj1195
    3955 最长严格上升子序列(加强版)
    1021 玛丽卡
  • 原文地址:https://www.cnblogs.com/gwj1314/p/9444692.html
Copyright © 2011-2022 走看看