讨论 / 为毛评测机上无输出。。。本机已AC
dby_is_nc 2013-11-04 03:50:56
点我顶贴 收藏 删除
#include <stdio.h>

const int INF = 10000;

int sum [1025], point;

struct node{

int lChild;

int rChild;

char value;

}tree [1025];

void rootBehind (int nod){

if (tree [nod].lChild == INF && tree [nod].rChild == INF)

printf ("%c", tree [nod].value);

else{

rootBehind (tree [nod].lChild);

rootBehind (tree [nod].rChild);

printf ("%c", tree [nod].value);

}

}

void treeBuild (int a, int b, int nod){

if (sum [b] - sum [a - 1] == 0)

tree [nod].value = 'B';

else if (sum [b] - sum [a - 1] == b - a + 1)

tree [nod].value = 'I';

else

tree [nod].value = 'F';

if (b == a){

tree [nod].lChild = INF;

tree [nod].rChild = INF;

}

else{

tree [nod].lChild = ++point;

tree [nod].rChild = ++point;

treeBuild (a, (a + b) / 2, tree [nod].lChild);

treeBuild ((a + b) / 2 + 1, b, tree [nod].rChild);

}

}

int main (){

int n, t = 1;

char* a;

scanf ("%d", &n);

for (int i = 0; i < n; i ++)t *= 2;

sum [0] = 0;

scanf ("%s", a);

for (int i = 1; i <= t; i ++)

sum [i] = sum [i - 1] + a [i - 1] - '0';

point = 1;

treeBuild (1, t, 1);

rootBehind (1);

return 0;

}

#1 huhang1996@2013-11-04 04:50:27
回复 删除
同问

查看更多回复
提交回复