AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

AcWing 419. FBI树    原题链接    简单

作者: 作者的头像   乡村守望者 ,  2019-10-14 19:44:12 ,  所有人可见 ,  阅读 644


0


思路

  • 递归运算
  • 若可再分,就左子树递归,右子树递归
  • 然后进行自身的计算即可

参考代码

#include<iostream>
using namespace std;
const int N = 15;
int n;
string str;
void Tree(int l,int r)
{
    if(l!=r)Tree(l,(l+r)/2);
    if(l!=r)Tree((l+r)/2+1,r);
    int len0=0,len1=0;
    string type;
    for(int i=l;i<=r;++i){
        if(str[i]=='0')len0++;
        else len1++;
    }
    if(len1==0)type="B";
    else if(len0==0)type="I";
    else type="F";
    cout<<type;
}
int main()
{
    cin>>n;
    cin>>str;
    Tree(0,str.size()-1);
    return 0;
}

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息