算法入门【FBI树】

[NOIP2004]FBI树

https://ac.nowcoder.com/acm/contest/21763/1013

Thinking Process

what a easy excersize! but i waste much time on input. DAMN IT!
Overall, judge the length of S first. if length == 1, output it directly. otherwise, construct the tree and finally judge the type of S and output type!

Code

#include<stdio.h>
#include<math.h>
#include<string>
#include<iostream>
using namespace std;
char s[10000];

void build(int l, int r) {
  if(l == r) {
    if(s[l] == '1') {
      printf("I");
      return ;
    } else {
      printf("B");
      return ;
    }
  }

  int mid = l + r >> 1;
  build(l, mid);
  build(mid + 1,  r);


  int b = 1, i = 1;
  for(int j = l; j <= r ;j ++) {
    if(s[j] == '0') i = 0;
    else  b = 0;
  }
  if(i == 0 && b == 0) printf("F");
  else if(i == 0 && b == 1) printf("B");
  else if(i == 1 && b == 0) printf("I");

}

int main() {
  int n;
  scanf("%d", &n);
  n = pow(2, n);
  for(int i = 1;i <= n;i ++) {
      cin >> s[i];
  }
  build(1, n);
} 

全部评论

相关推荐

07-18 15:02
门头沟学院 Java
刚打开网申页面就不想填了,还是不要为难自己了
poppinzhan...:多益老行业毒瘤了,碰到徐波这种恶心的烂人,去了也是受罪。
点赞 评论 收藏
分享
凉风落木楚山秋:哈工爷200也去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务