题解

132 条题解

  • 0
    @ 2009-10-31 10:38:14

    var i,j,n,m:integer;

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

    begin

    readln(n);m:=1;

    for i:=1 to n+1 do begin

    m:=m*2;

    end;

    m:=m-2;

    writeln(m);

    end.

  • 0
    @ 2009-10-29 23:25:59

    。。水题一道。。

    考虑最优移法只需要将上层的2*(n-1)个盘移动到第二根柱子,再将最后一个盘移动到目标,最后再将第二根柱子上的盘子全部移动到目标,得到的总步数为f[n]/2=2*f[n-1]+1,累推得f[n]=2^(n+1)-2。。然后高精就完了。。

  • 0
    @ 2009-10-27 22:22:35

    ???????????????????

  • 0
    @ 2009-10-27 17:01:41

    先无视2n的条件——有2n片的时候(因为每两片大小一样),要移动的次数正好是有n片的时候的1倍。有n片的时候:

    如果有1片,要移动1次;

    如果有2片,要移动3次;

    如果有3片,要移动7次;

    ……

    总结得到:hanoi(n)=hanoi(n-1)*2+1。

    有这一规律的原因是:要把n片的一座塔从柱子1移到柱子3,可以视作这样一个过程:

    Step 1:将n-1片的塔从柱子1-->柱子2;

    Step 2:将第n片,就是最大的一片,移到柱子3;

    Step 3:将柱子2上的n-1片塔移到柱子3的底座上。

    其中,

    Step 1需要移动hanoi(n-1)步;

    Step 2需要移动1步;

    Step 3需要移动hanoi(n-1)步;

    所以hanoi(n)=hanoi(n-1)*2+1。

    最后把结果乘以2.要用高精度。

  • 0
    @ 2009-10-26 23:06:40

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    简单递推...顺便复习了高精...

    求2^N-2我居然用了N次高精乘单精加一次高精减高精

  • 0
    @ 2009-10-24 23:42:55

    #include

    int main()

    {

    int n, j, a[70]={0,1}, w=1;

    for (scanf("%d", &n); n>0; n--,w+=(a[w+1]>0))

    for (j=w; j>0; j--) {

    a[j+1]+=(a[j]

  • 0
    @ 2009-10-24 19:49:13

    #include

    using namespace std;

    int n,a[1001],p=1;

    void pplt(void)

    {

    int i;

    for (i=1;i

  • 0
    @ 2009-10-17 17:14:20

    A(n)=2*A(n-1)+2;

    经典hanoi递推

  • 0
    @ 2009-10-10 07:58:27

    编译通过...

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

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

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

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

    ├ 测试数据 05:运行超时|无输出...

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

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

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

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

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

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

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

    rp很重要么??

    同样的程序…………

    编译通过...

    ├ 测试数据 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-27 10:55:21

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    program p1354;

    var a:array[1..2000] of longint;

    i,j,k,l,m,n:longint;

    begin

    readln(n); l:=1;

    for k:=1 to n do begin inc(a[1]);

    for i:=1 to l do

    a[i]:=a[i]*2;

    for i:=1 to l-1 do begin

    inc(a,a[i] div 10);

    a[i]:=a[i] mod 10; end;

    while a[l]>10 do begin

    a[l+1]:=a[l] div 10;a[l]:=a[l] mod 10;inc(l);

    end;

    end;

    for i:=l downto 1 do write(a[i]);

    end.

  • 0
    @ 2009-09-16 21:37:31

    这是啥呀???

    2 6 14 30 62 126 254 510 1022 2046 4094 8190 16382 32766 65534 131070 262142 524286 1048574 2097150 4194302 8388606 16777214 33554430 67108862 134217726 268435454 536870910 1073741822 2147483646 4294967294 8589934590 17179869182 34359738366 68719476734 137438953470 274877906942 549755813886 1099511627774 2199023255550 4398046511102 8796093022206 17592186044414 35184372088830 70368744177662 140737488355326 281474976710654 562949953421310 1125899906842622 2251799813685246 4503599627370494 9007199254740990 18014398509481982 36028797018963966 72057594037927934 144115188075855870 288230376151711740 576460752303423490 1152921504606847000 2305843009213694000 4611686018427387900 9223372036854775800 18446744073709552000 36893488147419103000 73786976294838207000 147573952589676410000 295147905179352830000 590295810358705650000 1180591620717411300000 2361183241434822600000 4722366482869645200000 9444732965739290500000 18889465931478581000000 37778931862957162000000 75557863725914324000000 151115727451828650000000 302231454903657290000000 604462909807314590000000 1208925819614629200000000 2417851639229258300000000 4835703278458516700000000 9671406556917033400000000 19342813113834067000000000 38685626227668134000000000 77371252455336267000000000 154742504910672530000000000 309485009821345070000000000 618970019642690140000000000 1237940039285380300000000000 2475880078570760600000000000 4951760157141521100000000000 9903520314283042200000000000 19807040628566084000000000000 39614081257132169000000000000 79228162514264338000000000000 158456325028528680000000000000 316912650057057350000000000000 633825300114114700000000000000 1267650600228229400000000000000 2535301200456458800000000000000 5070602400912917600000000000000 10141204801825835000000000000000 20282409603651670000000000000000 40564819207303341000000000000000 81129638414606682000000000000000 162259276829213360000000000000000 324518553658426730000000000000000 649037107316853450000000000000000 1298074214633706900000000000000000 2596148429267413800000000000000000 5192296858534827600000000000000000 10384593717069655000000000000000000 20769187434139311000000000000000000 41538374868278621000000000000000000 83076749736557242000000000000000000 166153499473114480000000000000000000 332306998946228970000000000000000000 664613997892457940000000000000000000

  • 0
    @ 2009-09-06 17:46:26

    第n个不是(2^n-1)*2吗?

    我只过了7个点,其他三个207了.

    不是exp(n*ln(2)-1)*2吗?

    请神牛们帮忙.

  • 0
    @ 2009-09-06 17:02:37

    这题,

    规律不是

    起始是2,然后N-1次*2+2吗?

    我怎么用 integer只对了20,用longint只对了50?

  • 0
    @ 2009-08-26 13:52:02

    高精度加法

    以及递推式f[n]=f[n-1]+f[n-1]+2

    足够AC

  • 0
    @ 2009-08-15 14:28:14

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    program NOIP_2007_4;

    var ans:array[0..62]of shortint;

    j,n:longint;

    procedure mul;

    var len,m,i:longint;

    begin

    len:=ans[0];

    for i:=1 to len do

    ans[i]:=ans[i]*2;

    for i:=1 to len do

    begin

    inc(ans,ans[i] div 10);

    ans[i]:=ans[i] mod 10;

    end;

    m:=ans[len+1];

    while m>0 do

    begin

    inc(len);

    ans[len]:=m mod 10;

    m:=m div 10;

    end;

    ans[0]:=len;

    end;

    begin

    readln(n);

    ans[0]:=1;ans[1]:=1;

    for j:=1 to n+1 do

    mul;

    dec(ans[1],2);

    for j:=ans[0] downto 1 do

    write(ans[j]);

    end.

    这、、这难道是第四题?

    木子日均是真的吗?好,我做麦森数去

  • 0
    @ 2009-08-12 11:02:57

    var n,i,j:longint;

    f:array[[blue]1[/blue]..[blue]500[/blue]] of longint;

    procedure chen(k:longint);

    var i,qian:longint;

    begin

    qian:=[blue]0[/blue];

    for i:= [blue]1[/blue] to [blue]500[/blue] do

    begin

    f[i]:=f[i]*k+qian;

    qian:=f[i] div [blue]10[/blue];

    f[i]:=f[i] mod [blue]10[/blue];

    end;

    end;

    begin

    fillchar(f,sizeof(f),[blue]0[/blue]);

    f[[blue]1[/blue]]:=1;

    readln(n);

    n:=n+[blue]1[/blue];

    for i:= [blue]1[/blue] to n div [blue]20[/blue] do

    chen([blue]1048576[/blue]);

    for i:= [blue]1[/blue] to n mod [blue]20[/blue] do

    chen([blue]2[/blue]);

    j:=[blue]500[/blue];

    while f[j] = [blue]0[/blue] do dec(j);

    for i:= j downto [blue]2[/blue] do write(f[i]);

    writeln(f[[blue]1[/blue]]-[blue]2[/blue]);

    end.

    饿。直接拿麦森数那题改改就过了..

  • 0
    @ 2009-08-01 16:09:30

    {超级无敌大高精搞笑版}

    program leo;

    var p:longint;

    s:array[1..70] of integer;

    i,j:longint;

    begin

    read(p);

    s[1]:=1;

    for j:=1 to p+1 do

    begin

    for i:=70 downto 1 do

    case s[i] of

    1 : s[i]:=2;

    2 : s[i]:=4;

    3 : s[i]:=6;

    4 : s[i]:=8;

    5 : begin s[i]:=0; inc(s,1); end;

    6 : begin s[i]:=2; inc(s,1); end;

    7 : begin s[i]:=4; inc(s,1); end;

    8 : begin s[i]:=6; inc(s,1); end;

    9 : begin s[i]:=8; inc(s,1); end;

    end;

    end;

    dec(s[1],2);

    for i:=1 to 70 do

    begin

    if s[i]>9 then begin inc(s,s[i] div 10);

    s[i]:=s[i] mod 10;

    end;

    if s[i]=0;

    end;

    for i:=70 downto 1 do if s[i]0 then break;

    for j:=i downto 1 do write(s[j]);

    end.

  • 0
    @ 2009-07-31 12:45:08

    program hanoi;

    type

    art=array[0..62]of longint;

    var

    a:art;

    n,i:longint;

    procedure mul2(var a:art);

    var

    i,t:longint;

    begin

    t:=0;

    a[0]:=62;

    while a[a[0]]=0 do dec(a[0]);

    for i:=1 to a[0]+1 do

    begin

    a[i]:=a[i]*2;

    inc(a[i],t);

    t:=a[i] div 10;

    a[i]:=a[i] mod 10;

    end;

    end;

    procedure dec2(var a:art);

    var

    i:longint;

    begin

    a[0]:=62;

    while a[a[0]]=0 do dec(a[0]);

    if a[1]>=2 then dec(a[1],2)

    else

    begin

    inc(a[1],8);

    for i:=2 to a[0] do

    begin

    if a[i]0 then

    begin

    dec(a[i]);

    break;

    end;

    a[i]:=9;

    end;

    end;

    end;

    procedure print(var a:art);

    var

    i:longint;

    begin

    a[0]:=62;

    while a[a[0]]=0 do dec(a[0]);

    for i:=a[0] downto 1 do write(a[i]);

    writeln;

    end;

    begin

    readln(n);

    if n=1 then

    begin

    writeln(2);

    halt;

    end;

    fillchar(a,sizeof(a),0);

    a[1]:=1;a[0]:=1;

    for i:=1 to n+1 do mul2(a);

    dec2(a);

    print(a);

    end.

    BS下Cheaters。。。

  • 0
    @ 2009-07-26 22:12:22

    交表时没用字符串

    结果出了科学计数法

    Cheat也要技术啊

  • 0
    @ 2009-07-26 18:56:20

    致楼下的楼下的楼下的楼下的楼下的楼下的楼下的楼下的楼下。。

    据说你内个叫Cheat。。

信息

ID
1354
难度
5
分类
动态规划 点击显示
标签
递交数
4925
已通过
1816
通过率
37%
被复制
18
上传者