题解

111 条题解

  • 0
    @ 2009-11-09 18:19:06

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-11-08 20:56:05

    明朗`了 就不难了

    虽然看上去晕乎乎的

  • 0
    @ 2009-11-07 10:15:56

    第2(2(2)+2(0))+2个AC

  • 0
    @ 2009-11-03 16:38:39

    怪兮兮的题,于是用怪兮兮的位运算....

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

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    var

    n:longint;

    function len(m:longint):longint;

    var i:longint;

    begin

    i:=0;

    while m0 do

    begin

    m:=m shr 1;

    inc(i);

    end;

    len:=i;

    end;

    procedure chuli(m:longint);

    var j,t:longint;

    begin

    while m0 do

    begin

    t:=len(m)-1;

    write('2');

    if t>2 then

    begin

    write('(');

    chuli(t);

    write(')');

    end

    else

    if t1 then write('(',t,')');

    m:=m xor (1 shl t);

    if m0 then write('+');

    end;

    end;

    begin

    readln(n);

    if n=0 then write(0) else chuli(n);

    end.

  • 0
    @ 2009-10-26 20:07:38

    program micifangof2;

    var n:integer;

    procedure countof2(n:integer;var a,b:integer);

    var i:integer;

    begin

    a:=0;

    b:=1;

    repeat;

      inc(a);

      b:=b*2;

    until b>n;

    dec(a);

    b:=b div 2;

    end;

    procedure work(n:integer);

    var a,b:integer;

    begin

    while n>0 do

      begin

       countof2(n,a,b);

       case a of

        0:write('2(0)');

        1:write(2);

        else

         begin

          write('2(');

          work(a);

          write(')');

         end;

       end;

       n:=n-b;

       if n>0 then write('+');

      end;

    end;

    begin

    readln(n);

    work(n);

    end.

  • 0
    @ 2009-10-25 14:35:30

    我用递归怎么会有两个超时呢?难道评测机的问题?

    program micifangof2;

    var n:integer;

    procedure countof2(n:integer;var a,b:integer);

    var i:integer;

    begin

    a:=0;

    b:=1;

    repeat;

    inc(a);

    b:=b*2;

    until b>n;

    dec(a);

    b:=b div 2;

    end;

    procedure work(n:integer);

    var a,b:integer;

    begin

    while n>0 do

    begin

    countof2(n,a,b);

    case a of

    0:write('2(0)');

    1:write(2);

    else

    begin

    write('2(');

    work(a);

    write(')');

    end;

    end;

    n:=n-b;

    if n>0 then write('+');

    end;

    end;

    begin

    readln(n);

    work(n);

    end.

  • 0
    @ 2009-10-25 00:03:49

    简单的递归式输出。。。

    ======================晒程序========================

    var

    d:array[0..21] of longint;

    n,i:longint;

    procedure print(n:longint);

    var

    i:longint;

    begin

    if n=1 then begin

    write('2(0)');

    exit;

    end;

    for i:=1 to 19 do if d>n then break;

    while n>1 do begin

    write('2');

    if i>1 then begin

    write('(');

    print(i);

    write(')');

    end;

    n:=n-d[i];

    if n>0 then write('+');

    while d[i]>n do dec(i);

    end;

    if n=1 then print(n);

    end;

    begin

    readln(n);

    for i:=1 to 20 do d[i]:=1 shl i;

    print(n);

    writeln();

    end.

  • 0
    @ 2009-10-24 20:56:20

    犯了个低级错误。。。取二进制最高位的2不是div 2,div 2 是shr 1。。。想了我好半天。 话说,取最低位的1是 p and -not p ??,取最高位呢??

  • 0
    @ 2009-10-24 16:58:11

    递归

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-10-23 10:32:00

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    program ex;

    var i,j,n,mi,now:longint;

    f:array[1..100000]of ansistring;

    procedure main;

    var i,j:longint;

    begin

    f[1]:='2(0)';

    f[2]:='2';

    mi:=1;

    now:=2;

    i:=3;

    while i

  • 0
    @ 2009-10-21 17:21:07

    我是类似按字符串的方法做的,没递归。

    贴一下程序,仅供BS。

    const mset:set of byte=[3..15]; nset:set of byte=[ord('0')..ord('9')];var stack:array[0..15]of byte; ans:ansistring; s:string[3]; i,j,k:word; flag,finish:boolean; top:word; n:word;procedure make(l,r,k:word);var temp:ansistring; i:word;begin top:=0; fillchar(stack,sizeof(stack),0); while k0 do begin stack[top]:=k and 1; k:=k shr 1; inc(top); end; temp:=''; for top:=0 to top do begin if stack[top]=0 then continue; str(top,s); if top1 then temp:='2('+s+')+'+temp else temp:='2+'+temp; end; delete(temp,length(temp),1); delete(ans,l,r-l+1); insert(temp,ans,l);end;begin readln(n); top:=0; ans:=''; while(n0)do begin stack[top]:=n and 1; n:=n shr 1; inc(top); end; for top:=0 to top do begin if stack[top]=0 then continue; str(top,s); if top1 then ans:='2('+s+')+'+ans else ans:='2+'+ans; end; delete(ans,length(ans),1); repeat finish:=true; for i:= length(ans) downto 1 do if ans[i]=')' then begin for j:=i downto 1 do if ans[j]='(' then break; if j=1 then continue; flag:=true; for k:=j+1 to i-1 do if (ord(ans[k])) in nset =false then begin flag:=false; break; end; if flag=false then continue; val(copy(ans,j+1,i-j-1),k); if k in mset then begin make(j+1,i-1,k); finish:=false; break; end; end; until finish; writeln(ans);end.

  • 0
    @ 2009-10-14 21:41:17

    不用递归 哈哈

    const a:array[-1..14]of string=('0','2(0)','2','2(2)','2(2+2(0))','2(2(2))','2(2(2)+2(0))','2(2(2)+2)','2(2(2)+2+2(0))','2(2(2+2(0)))','2(2(2+2(0))+2(0))','2(2(2+2(0))+2)','2(2(2+2(0))+2+2(0))','2(2(2+2(0))+2(2))','2(2(2+2(0))+2(2)+2(0))','2(2(2+2(0))+2(2)+2)');

    var i,j,k,n:longint;

    s:string;

    f:array[0..10000]of longint;

    begin

    readln(n);

    i:=n;

    j:=0;

    while i>0 do

    begin

    f[j]:=i mod 2;

    i:=i div 2;

    inc(j);

    end;

    if n=0 then writeln(a[-1]) else

    begin

    s:='';

    for i:=0 to j-1 do if f[i]0 then s:=a[i]+'+'+s;

    delete(s,length(s),length(s));

    writeln(s);

    end;

    end.

  • 0
    @ 2009-10-13 23:37:56

    const sec:array[0..15] of longint=(1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768);

    var n:integer;

    procedure get(n:integer);

    var i,m:integer;

    begin

    i:=15; m:=n;

    while m>0 do

    begin

    while m1 then begin write('2(');get(i);write(')');end

    else if i=1 then write('2')

    else if i=0 then write('2(0)');

    if m>0 then write('+');

    end;

    end;

    begin

    readln(n);

    get(n);

    end.

    觉得我比大家都简单……

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-10-27 18:57:20

    var

    a:array[0..20]of boolean;

    i,k,n,t:integer;

    procedure print(n:integer);

    begin

    case n of

    0:write('(0)');

    2:write('(2)');

    3:write('(2+2(0))');

    4:write('(2(2))');

    5:write('(2(2)+2(0))');

    6:write('(2(2)+2)');

    7:write('(2(2)+2+2(0))');

    8:write('(2(2+2(0)))');

    9:write('(2(2+2(0))+2(0))');

    10:write('(2(2+2(0))+2)');

    11:write('(2(2+2(0))+2+2(0))');

    12:write('(2(2+2(0))+2(2))');

    13:write('(2(2+2(0))+2(2)+2(0))');

    14:write('(2(2+2(0))+2(2)+2)');

    end;

    end;

    begin

    readln(n);

    k:=-1; t:=-1;

    fillchar(a,sizeof(a),false);

    while n>0 do

    begin

    inc(k);

    if odd(n) then a[k]:=true;

    if (t=-1)and(odd(n)) then t:=k;

    n:=n div 2;

    end;

    for i:= k downto t do

    if a[i] then

    begin

    write('2'); print(i);

    if it then write('+');

    end;

    end.

    直接打表得了……

  • 0
    @ 2009-10-07 20:03:28

    第2(2(2+2(0))+2(0))+2(2(2)+2)+2(2)+2个AC

  • 0
    @ 2009-10-06 12:01:27

    一开始少输出了一个'('

    结果。。。

    编译通过...

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

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

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

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

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

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

    ├ 测试数据 07:答案错误... ├ 标准行输出

     ├ 错误行输出

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

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

    ├ 测试数据 10:答案错误... ├ 标准行输出

     ├ 错误行输出

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

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

    查了好久。。。才

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-10-05 16:18:45

    好明显的二进制。递归就行了

  • 0
    @ 2009-10-03 17:36:38

    program p1597;

    var

    i,j,k,n,m,s,t:longint;

    procedure sol(m,de:longint);

    var

    i,j,k:longint;

    begin

    if m=0 then

    begin

    write(0);

    exit;

    end;

    if m=1 then

    begin

    write(2);

    if de1 then

    begin

    write('(');

    if (de=0)or(de=2) then write(de)

    else sol(de,0);

    write(')');

    end;

    exit;

    end;

    if m mod 20 then

    begin

    sol(m shr 1,de+1);

    write('+');

    write(2);

    if de1 then

    begin

    write('(');

    if (de=0)or(de=2) then write(de)

    else sol(de,0);

    write(')');

    end;

    end

    else

    sol(m shr 1,de+1);

    end;

    begin

    readln(n);

    sol(n,0);

    writeln;

    end.

    超级简洁版!~

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-09-25 21:14:25

    program p1597;

    var

    s:array[0..1] of string;

    n:longint;

    procedure fenjie(n:integer);

    var

    t,k:longint;

    begin

    if n=0 then exit;

    if n=1 then write(s[0])

    else if n=2 then write(s[1])

    else begin

    t:=1; k:=0;

    while tt then begin write('+'); fenjie(n-t); end;

    end;

    end;

    begin

    read(n);

    s[0]:='2(0)';

    s[1]:='2';

    fenjie(n);

    end.

    不停的递归,不过{}中的k=1和0的情况需要特判

  • 0
    @ 2009-09-25 10:19:20

    1次AC(虽然这只是水题。。。)

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

信息

ID
1597
难度
3
分类
模拟 点击显示
标签
递交数
2824
已通过
1420
通过率
50%
被复制
10
上传者