- FBI树
- 2009-01-19 10:46:35 @
program fbi;
var
a:array[1..1024] of char;
i,n,t:integer;
c:char;
function fbi(l,r:integer):char;
var
c1,c2:char;
begin
if r=l+1 then
begin
write(a[l],a[r]);
if a[l]a[r] then exit('F')
else
if a[l]='I' then exit('I')
else exit('B');
end
else
begin
c1:=fbi(l,(l+r)div 2);write(c1);
c2:=fbi((l+r+1)div 2,r);write(c2);
if c1=c2 then exit(c1)
else exit('F');
end;
end;
begin
readln(n); t:=1;
for i:=1 to n do t:=t*2;
for i:=1 to t do
begin
read(c);
if c='0' then a[i]:='B'
else a[i]:='I';
end;
writeln(fbi(1,t));
end.
???
2 条评论
-
Jerome_wei LV 8 @ 2016-08-27 14:14:46
是不是数组开大了
-
2013-03-29 17:14:30@
我也是
var
n,i:word;
f,t:ansistring;
s:char;
procedure buildt(p:ansistring;da:word);
var bb,ii:boolean; k,i:word;
begin
bb:=false;ii:=false;
for i:=1 to length(p) do
if f[i]='B' then
if ii then
begin
t[da]:='F'; k:=length(p)div 2;
buildt(copy(p,1,k),da*2);
buildt(copy(p,k+1,k),da*2+1);
exit;
end else{if ii}
begin bb:=true;t[da]:='B'; end
else
if bb then
begin
t[da]:='F'; k:=length(p)div 2;
buildt(copy(p,1,k),da*2);
buildt(copy(p,k+1,k),da*2+1);
exit;
end else{if bb}
begin ii:=true;t[da]:='I'; end;
buildt(copy(p,1,k),da*2);
buildt(copy(p,k+1,k),da*2+1);
end;
procedure out(da:word);
begin
if length(t[da])>1 then
begin
out(da*2);out(da*2+1);write(t[da]);
end else write(t[da]);
end;
begin
readln(n); i:=0; f:='';
while not eoln do
begin
read(s); inc(i);
if s='0' then f[i]:='B'
else f[i]:='I';
end;
buildt(f,1);
out(1);
end.
- 1