- FBI树
- 2015-02-09 14:44:22 @
在隔壁wikioi上AC的程序……这里挂掉了……
program haer;
type
node=^rec;
rec=record
data:char;
left,right:node;
end;
var
a:array[1..1024] of char;
n,i:integer;
root:node;
procedure sqrr(var nn:integer);
var
ii,mm:integer;
begin
mm:=1;
for ii:=1 to nn do
mm:=mm*2;
nn:=mm;
end;
procedure make(l,r:integer;q:node);
var
ii:integer;
flb,fli,flf:0..1;
lth:integer;
mid:integer;
begin
if l=r then
case a[l] of
'0':q^.data:='B';
'1':q^.data:='I';
end
else
begin
flf:=0;
flb:=0;
fli:=0;
for ii:=l to r do
begin
if a[ii]='0' then flb:=1;
if a[ii]='1' then fli:=1;
if (fli=1)and(flb=1) then
begin
flf:=1;
flb:=0;
fli:=0;
break;
end;
end;
if flf=1 then q^.data:='F';
if flb=1 then q^.data:='B';
if fli=1 then q^.data:='I';
lth:=r-l+1;
mid:=l+(lth div 2)-1;
new(q^.left);
new(q^.right);
make(l,mid,q^.left);
make(mid+1,r,q^.right);
end;
end;
procedure post(cao:node); {后序遍历}
begin
if cao^.left<>nil then post(cao^.left);
if cao^.right<>nil then post(cao^.right);
write(cao^.data);
end;
begin
readln(n);
sqrr(n);
for i:=1 to n do
read(a[i]);
new(root);
make(1,n,root);
post(root);
end.
大神们求助(┬_┬)
1 条评论
-
琉璃盏 LV 10 @ 2015-02-09 17:39:18
人品
- 1