/ Vijos / 题库 / FBI树 /

题解

157 条题解

  • 0
    @ 2008-11-13 18:59:14

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    其实很水啊~~~总共25行0ms过~~

    PS:其实根本不用建树~~~~~

    附:

    var fib:ansistring;

    n,i:integer;

    x,y:char;

    procedure find(p,q:integer);

    begin

    if pq then begin find(p,(p+q) div 2); find((p+q) div 2+1,q); end;

    if pos('0',copy(fib,p,q-p+1))=0 then write('I')

    else if pos('1',copy(fib,p,q-p+1))=0 then write('B')

    else write('F');

    end;

    begin

    readln(n);

    read(fib);

    if n=0 then

    begin

    if fib='0' then write('B') else if fib='1' then write('I') else write('F');

    halt;

    end;

    find(1,trunc(exp(n*ln(2))));

    end.

    注意用ansistring!!

  • 0
    @ 2008-11-13 12:28:57

    我向党承认错误:

    ansistring不能乱用阿!!

    否则 .1&&.10 打死也过不了~~~~

  • 0
    @ 2008-11-11 20:24:34

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    第一次一次ac noip题……

    貌似是用深度优先做的……

    先两个……递归左右树,最后判断根

    k:=(i+j) div 2;

    trytry(i,k,ch1);

    trytry(k+1,j,ch2);

    if (ch1=ch2) then begin write(ch1);ch:=ch1;end

    else begin write('F');ch:='F';end;

    差不多就这个意思……献丑了哈!……

  • 0
    @ 2008-11-07 14:13:19

    可以加上一个显而易见的优化

    当x节点的值为'B' or 'I'时 可以直接传递到子树

    const wd:array[-1..1] of char=('F','B','I');

    procedure buildtree(l,r,c:integer);

    var mid,i,k:integer;

    w:array[0..1] of boolean;

    begin

    if l=r then

    begin

    if p[l]=1 then write('I') else write('B');

    exit;

    end;

    if l>r then exit;

    k:=c;

    mid:=(l+r)div 2;

    if c=-1 then begin

    w[0]:=false;w[1]:=false;

    for i:=l to r do w[p[i]]:=true;

    if w[0] and w[1] then k:=-1

    else if w[0] then k:=0 else k:=1;

    end;

    buildtree(l,mid,k);

    buildtree(mid+1,r,k);

    write(wd[k]);

    end;

  • 0
    @ 2008-11-05 23:13:10

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    做水题有益健康

  • 0
    @ 2008-11-04 18:20:13

    program fbi;

    var

    a,f:array[1..100000]of char;

    i,j,n:integer;

    function try3(i,n:longint):longint;

    var

    k:longint;

    begin try3:=1;

    for k:=1 to n do

    try3:=try3*i;end;

    procedure ty(i:integer);

    begin

    if f[i]' '

    then begin ty(2*i);ty(2*i+1); write(f[i]:1);end

    end;

    procedure try(i:integer);

    var

    b:array[1..15]of set of char;

    begin

    fillchar(b,sizeof(b),'4');

    b[1]:=[f]+[f];

    if b[1]=['B']then f[i]:='B';if b[1]=['I']then f[i]:='I';

    if (b[1]=['B','I'])or(b[1]=['F'])or(b[1]=['F','B'])or(b[1]=['F','I'])

    then f[i]:='F';end;

    begin

    fillchar(f,sizeof(f),' ');

    readln(n);

    for i:=1 to try3(2,n) do begin

    read(a);

    f[try3(2,n)-1+i]:=a[i];

    if f[try3(2,n)-1+i]='3'then f[try3(2,n)-1+i]:='F';

    if f[try3(2,n)-1+i]='1'then f[try3(2,n)-1+i]:='I';

    if f[try3(2,n)-1+i]='0'then f[try3(2,n)-1+i]:='B'; end;

    for i:=try3(2,n)-1 downto 1 do try(i); ty(1);writeln;

    end.

  • 0
    @ 2008-11-02 21:31:58

    n=0 害死我

  • 0
    @ 2008-11-02 10:47:12

    终于发现递归的精简之处了

    function print(now:ansistring):longint;

    var

    sl,sr : ansistring;

    len,l,r : longint;

    begin

    if length(now)=1 then begin

    if now='1' then begin write('I') ;exit(1);end else

    begin write('B');exit(0);end;

    end;

    len:=length(now);

    sl:=copy(now,1,len div 2);

    sr:=copy(now,len div 2+1,len div 2);

    l:=print(sl);r:=print(sr);

    if l=r then begin

    if l=1 then begin write('I');exit(1);end

    else if l=0 then begin write('B');exit(0);end else

    begin write('F');exit(2);end;

    end else begin

    write('F');

    exit(2);

    end;

    end;

  • 0
    @ 2008-11-02 10:24:49

    type tree=^node;

    node=record

    data:char; l,r:tree;

    end;

    var head:tree; n:longint;

    procedure build(head:tree; st:ansistring);

    var i,k:word; ls,rs:ansistring;

    begin

    if length(st)=1 then

    begin

    if st[1]='0' then head^.data:='B' else head^.data:='I';

    exit;

    end;

    k:=length(st); k:=k div 2;

    ls:=copy(st,1,k); rs:=copy(st,k+1,k);

    new(head^.l); build(head^.l,ls);

    new(head^.r); build(head^.r,rs);

    if head^.l^.data=head^.r^.data then head^.data:=head^.l^.data else head^.data:='F';

    end;

    procedure init;

    var i,k,j:longint; st:ansistring;

    begin

    readln(n); readln(st);

    while st[length(st)]=' ' do delete(st,length(st),1);

    new(head); build(head,st);

    end;

    procedure print(head:tree);

    begin

    if head^.l=nil then

    begin

    write(head^.data); exit;

    end;

    print(head^.l); print(head^.r); write(head^.data);

    end;

    begin

    init;

    print(head);

    end.

  • 0
    @ 2008-10-30 21:31:06

    编译通过...

    ├ 测试数据 01:运行超时...

    ├ 测试数据 02:运行超时...

    ├ 测试数据 03:运行超时...

    ├ 测试数据 04:运行超时...

    ├ 测试数据 05:运行超时...

    ├ 测试数据 06:运行超时...

    ├ 测试数据 07:运行超时...

    ├ 测试数据 08:运行超时...

    ├ 测试数据 09:运行超时...

    ├ 测试数据 10:运行超时...

    ---|---|---|---|---|---|---|---|-

    Unaccepted 有效得分:0 有效耗时:0ms

    这种题目竟然也能超时???

  • 0
    @ 2008-10-30 17:59:53

    program fbi;

    const pre:array[0..10]of integer=(1,2,4,8,16,32,64,128,256,512,1024);

    var f:array[1..2049]of char;

    a:array[1..1025]of integer;

    i,j,k,n:longint;

    ch:char;

    procedure work(x,y:longint);

    var i:longint;

    begin

    i:=x;

    while i

  • 0
    @ 2008-10-27 21:21:13

    一次性AC

  • 0
    @ 2008-10-22 13:39:35

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    郁闷郁闷....本来以为要防止n=0的情况,就加了一句:

    if n=0 then exit;

    结果....我的AC率........

  • 0
    @ 2008-10-17 17:27:33

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2008-10-15 13:10:54

    注意n=0的情况,此时应不再读入ansistring,直接输出'B'...

    开始没注意,90...第二点超时。.....。

  • 0
    @ 2008-10-16 20:54:21

    不知道我是否火星了

    有沒人這樣做的?

    4 F___|\__|_

    3 F___|F\
    __|

    2 F_B_F_I_

    1 IBBBIBII

    原 10001011

    Tree[x, y]的左孩子 = Tree[x-1, y]

    Tree[x, y]的右孩子 = Tree[x-1, y+2^(x-2)]

    啊哈哈,AnsiString我抛棄了你,投向CharArray的XXOO......

  • 0
    @ 2008-10-08 20:31:50

    program p1114;

    var

    n :longint;

    ty :array[0..1025,0..1025] of integer;

    sum :array[0..1025] of integer;

    procedure init;

    var

    i ,j ,sum1 :integer;

    temp :ansistring;

    begin

    readln(n);

    n:=1 shl n;

    sum1:=0;

    readln(temp);

    for i:=1 to n do

    begin

    if temp[i]='1' then

    inc(sum1);

    sum[i]:=sum1;

    end;

    for i:=1 to n do

    for j:=i to n do

    ty:=sum[j]-sum;

    end;

    procedure solve(i,j:integer);

    var

    m :integer;

    begin

    m:=(i+j) shr 1;

    if ji then

    begin

    solve(i,m);

    solve(m+1,j);

    end;

    if ty=j-i+1 then

    begin

    write('I');

    exit;

    end;

    if ty=0 then

    begin

    write('B');

    exit;

    end;

    write('F');

    end;

    begin

    init;

    solve(1,n);

    end.

  • 0
    @ 2008-10-01 15:42:04

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    1次AC

  • 0
    @ 2008-09-22 15:59:11

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    忽略了字符串的长度,使用了string,浪费了一次AC的机会!

  • 0
    @ 2008-09-12 19:48:21

    var

    i,j,k,l,f,b,n:longint;

    m:ansistring;

    function li(m:ansistring):char;

    var

    s0,s1:longint;

    begin

    s0:=0;

    s1:=0;

    for l:=1 to length(m) do

    if m[l]='0'

    then s0:=s0+1

    else s1:=s1+1;

    if s0=0

    then li:='I'

    else IF s1=0

    then li:='B'

    ELSE li:='F';

    END;

    procedure run(m:string);

    begin

    if length(m)>1

    then begin

    run(copy(m,1,length(m) div 2));

    run(copy(m,length(m)div 2+1,length(m)));

    end;

    write(li(m));

    end;

    begin

    readln(n);

    read(m);

    run(m);

    END.

    80啊 为什么? 请大牛们讲解一下!!!

信息

ID
1114
难度
3
分类
数据结构 | 点击显示
标签
递交数
4151
已通过
2216
通过率
53%
被复制
26
上传者