题解

294 条题解

  • 0
    @ 2009-08-17 17:32:45

    初学者可以用递归 回溯来做 注意总方法的数据类型应该为longint

  • 0
    @ 2009-08-11 16:57:03

    用动归做的

    #include

    #define M 16

    int f[M][M];

    int fa(int i,int j)

    {

    if(i

  • 0
    @ 2009-08-10 23:01:46

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

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

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

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

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

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

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

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

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

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

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

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

    var

    map:array[-2..16,-2..16] of longint;

    x,y,n,m,sum:longint;

    procedure run(x1,y1:integer);

    var

    i,j,k:longint;

    begin

    if y1>y then exit; if x1>x then exit;

    if map[x1,y1]=1 then begin inc(sum); exit; end;

    if map[x1+1,y1]2 then run(x1+1,y1);

    if map[x1,y1+1]2 then run(x1,y1+1);

    end;

    begin

    readln(x,y,n,m);

    map[x,y]:=1; map[n,m]:=2; map[n+2,m+1]:=2; map[n+2,m-1]:=2; map[n+1,m-2]:=2; map[n-1,m-2]:=2; map[n+1,m+2]:=2; map[n-1,m+2]:=2; map[n-2,m+1]:=2; map[n-2,m-1]:=2;

    run(0,0);

    write(sum);

    end.

    递归的,没秒杀是个遗憾。。。。。

  • 0
    @ 2009-08-09 12:02:45

    递推王道啊

  • 0
    @ 2009-08-07 22:00:12

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

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

    简单的搜索。

    program p1121;

    const dx:array[1..8] of -2..2=(-2,-2,-1,-1,1,1,2,2);

    dy:array[1..8] of -2..2=(1,-1,2,-2,2,-2,1,-1);

    gox:array[1..2] of 0..1=(0,1);

    goy:array[1..2] of 0..1=(1,0);

    var map:array[-2..17,-2..17] of boolean;

    n,m,x,y,total,i:longint;

    procedure findway(a,b:longint);

    var i:longint;

    begin

    if (a=n)and(b=m) then

    begin

    inc(total);

    exit;

    end;

    for i:=1 to 2 do

    if map[a+gox[i],b+goy[i]] then findway(a+gox[i],b+goy[i]);

    end;

    begin

    readln(n,m,x,y);

    fillchar(map,sizeof(map),true);

    map[x,y]:=false;

    for i:=1 to 8 do

    map[x+dx[i],y+dy[i]]:=false;

    for i:=0 to n do map:=false;

    for i:=0 to m do map[n+1,i]:=false;

    total:=0;

    findway(0,0);

    writeln(total);

    end.

  • 0
    @ 2009-08-04 22:25:05

    用integer只有60分!!要用longint!!

    编译通过...

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

     ├ 错误行输出

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

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

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

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

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

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

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

     ├ 错误行输出

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

     ├ 错误行输出

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

     ├ 错误行输出

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

    Unaccepted 有效得分:60 有效耗时: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-08-04 15:22:22

    const

    fx:array[1..8,1..2] of longint=((1,2),(1,-2),(2,1),(2,-1),(-1,2),(-1,-2),(-2,-1),(-2,1));

    var a:array[-2..100,-2..100] of longint;

    n,m,x,y,i,j,k:longint;

    begin

    read(n,m,x,y);

    a[x,y]:=-1;

    for i:=1 to 8 do a[x+fx,y+fx]:=-1;

    a[0,-1]:=1;

    for i:=0 to n do for j:=0 to m do if a=-1 then a:=0 else a:=a+a;

    writeln(a[n,m]);

    end.

  • 0
    @ 2009-08-03 17:09:10

    var

    map :array[0..16,0..16]of longint;

    n,m,x,y :longint;

    ans :longint;

    dir :longint;

    ddx :array[1..8]of longint=(-2,-1,1,2,-2,-1,1,2);

    ddy :array[1..8]of longint=(1,2,2,1,-1,-2,-2,-1);

    tx,ty :longint;

    i,j :longint;

    procedure find(x,y:longint);

    begin

    if (x=0)and(y=0) then begin inc(ans);exit; end;

    if map[x][y]=2 then begin inc(ans);exit; end;

    if ((x-1)>=0)and((map[x-1][y]=1)or(map[x-1][y]=2)) then find(x-1,y);

    if ((y-1)>=0)and((map[x][y-1]=1)or(map[x][y-1]=2)) then find(x,y-1);

    end;

    begin

    readln(n,m,x,y);

    for i:=0 to n do

    for j:=0 to m do

    map[i][j]:=1;

    map[x][y]:=0;

    for dir:=1 to 8 do begin

    tx:=x+ddx[dir];

    ty:=y+ddy[dir];

    if (tx>=0)and(tx=0)and(ty

  • 0
    @ 2009-08-01 23:45:01



    这样也AC

    const dx:array[1..8] of integer=(-1,-2,-2,-1,1,2,2,1);

    dy:array[1..8] of integer=(-2,-1,1,2,2,1,-1,-2);

    var a:array[0..25,0..25] of longint;

    b,c,d,n,m,e,i,j,f,mi,mj:longint;

    k,l:array[1..8] of integer;

    z:boolean;

    begin

    read(n,m,mi,mj);

    k:=dx;

    l:=dy;

    inc(mi);

    inc(mj);

    for i:=1 to 8 do begin

    k[i]:=k[i]+mi;

    l[i]:=l[i]+mj;

    end;

    for i:=1 to n+1 do

    for j:=1 to m+1 do a:=0;

    for i:=1 to 8 do a[k[i],l[i]]:=0;

    a[1,1]:=1;

    for i:=1 to n+1 do

    for j:=1 to m+1 do begin

    z:=true;

    for b:=1 to 8 do if (i=k) and (j=l) or ((i=mi) and (j=mj)) or (i=1) and (j=1) then z:=false;

    if z then a:=a+a;

    end;

    write(a[n+1,m+1]);

    end.

  • 0
    @ 2009-07-28 17:20:28

    来个短点的

    const fx:array[1..8,1..2] of longint=((1,2),(1,-2),(2,1),(2,-1),(-1,2),(-1,-2),(-2,-1),(-2,1));

    var a:array[-2..100,-2..100] of longint;

    n,m,x,y,i,j,k:longint;

    begin

    read(n,m,x,y);

    a[x,y]:=-1;

    for i:=1 to 8 do a[x+fx,y+fx]:=-1;

    a[0,-1]:=1;

    for i:=0 to n do for j:=0 to m do if a=-1 then a:=0 else a:=a+a;

    writeln(a[n,m]);

    end.

  • 0
    @ 2009-07-27 18:17:15

    var a:array[0..100,0..100] of longint;

    f:array[0..100,0..100] of boolean;

    n,m,n1,m1,i,j:integer;

    begin

    read(n,m,n1,m1);

    fillchar(f,sizeof(f),true);

    if (n1-2>=0) and (n1-2=0) and (m1-1=0) and (n1-2=0) and (m1+1=0) and (n1-1=0) and (m1-2=0) and (n1+1=0) and (m1-2=0) and (n1+2=0) and (m1-1=0) and (n1+2=0) and (m1+1=0) and (n1-1=0) and (m1+2=0) and (n1+1=0) and (m1+2

  • 0
    @ 2009-07-27 14:51:56

    提交的时候忘记把Debug的代码删掉,浪费了一次

    递推即可

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    var map:array[-100..100,-100..100,1..2] of ansistring;

    ex,ey,mx,my:longint;

    a,b:longint;

    c,d:boolean;

    procedure huan(var a,b:char);

    var c:char;

    begin

    c:=a;

    a:=b;

    b:=c;

    end;

    procedure dao(var a:ansistring);

    var b:longint;

    begin

    for b:=1 to length(a)div 2 do

    huan(a[ b ],a[length(a)-b+1]);

    end;

    function plus(a,b:ansistring):ansistring;

    var c,d,p,tmp1,tmp2,tmp3,k:longint;

    tmp4:string;

    begin

    dao(a);

    dao(b);

    while length(a)length(b) do

    insert('0',b,length(b)+1);

    setlength(plus,length(a)+1);

    for c:=1 to length(plus) do

    plus[c]:='0';

    k:=0;

    for c:=1 to length(a) do

    begin

    val(a[c],tmp1);

    val(b[c],tmp2);

    k:=tmp1+tmp2+k;

    str(k mod 10,tmp4);

    plus[c]:=tmp4[1];

    k:=k div 10;

    end;

    if k0 then

    begin

    str(k,tmp4);

    plus[length(plus)]:=tmp4[1];

    end;

    dao(plus);

    while (length(plus)>1)and(plus[1]='0') do delete(plus,1,1);

    end;

    begin

    for a:=-100 to 100 do

    for b:=-100 to 100 do

    begin

    map[a,b,1]:='0';

    map[a,b,2]:='0';

    end;

    read(ex,ey,mx,my);

    map[mx,my,2]:='1';

    map[mx-1,my-2,2]:='1';

    map[mx+1,my-2,2]:='1';

    map[mx+2,my-1,2]:='1';

    map[mx-2,my-1,2]:='1';

    map[mx+2,my+1,2]:='1';

    map[mx-2,my+1,2]:='1';

    map[mx-1,my+2,2]:='1';

    map[mx+1,my+2,2]:='1';

    if map[ex,ey,2]='1' then

    begin

    write(0);

    halt;

    end;

    c:=true;

    d:=true;

    for a:=0 to 100 do

    begin

    if (c)and(map[0,a,2]'1') then

    map[0,a,1]:='1'

    else c:=false;

    if (d)and(map[a,0,2]'1') then

    map[a,0,1]:='1'

    else d:=false;

    if (d=false)and(c=false) then break;

    end;

    for a:=1 to ex do

    for b:=1 to ey do

    if map[a,b,2]'1' then map[a,b,1]:=plus(map[a-1,b,1],map[a,b-1,1]);

    write(map[ex,ey,1]);

    end.

  • 0
    @ 2009-07-23 22:34:53

    编译通过...

    ├ 测试数据 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-07-23 16:43:51

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    program p1121(input,output);

    var ab:array [-5..20,-5..20] of longint;

    boo:array [-5..20,-5..20] of boolean;

    n,m,m1,m2,a,b:longint;

    begin

    readln(n,m,m1,m2);

    for a:=-5 to 20 do

    for b:=-5 to 20 do

    begin

    boo[a,b]:=true;

    ab[a,b]:=0;

    end;

    ab[0,0]:=1;

    boo[m1,m2]:=false;

    boo[m1-1,m2-2]:=false;

    boo[m1-1,m2+2]:=false;

    boo[m1-2,m2-1]:=false;

    boo[m1-2,m2+1]:=false;

    boo[m1+1,m2-2]:=false;

    boo[m1+2,m2-1]:=false;

    boo[m1+1,m2+2]:=false;

    boo[m1+2,m2+1]:=false;

    for a:=1 to n do

    if boo[a,0]

    then ab[a,0]:=ab[a-1,0];

    for b:=1 to m do

    if boo[0,b]

    then ab[0,b]:=ab[0,b-1];

    for a:=1 to n do

    for b:=1 to m do

    if boo[a,b]

    then ab[a,b]:=ab[a-1,b]+ab[a,b-1];

    writeln(ab[n,m]);

    end.

  • 0
    @ 2009-07-22 09:13:22

    #include

    #include

    long a[16][16],n,m,x,y,sum;

    int find(long i,long j)

    {

    if(i==n && j==m) sum++;

    else{

    if(a[i][j]==0 && i+1

  • 0
    @ 2009-07-21 17:20:15

    #include

    #include

    using namespace std;

    int xb,yb,xm,ym;

    int Ns[1000][1000];

    int gz[1000][1000];

    int m=0;

    void InIt()

    {

    cin>>xb>>yb>>xm>>ym;

    }

    void work()

    {

    for(int i=0;i

  • 0
    @ 2009-07-21 09:46:17

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    路过....原题里的数据范围是20 的。。。

  • 0
    @ 2009-07-18 11:25:04

    SO easy!! 没看到A(0,0) ,花了我半个多小时。。。

    递推做就可以,练下搜(记忆的能秒杀)也不错 可以用横纵坐标到马距离的和为3来判断,注意横纵坐标都不能和马的一样就行

    注意:

    1.递推注意初始条件 2.搜索注意终止条件

  • 0
    @ 2009-07-15 16:07:52

    program das;

    var n,m,x,y,z:longint;

    a:array[0..15,0..15] of 0..1;

    procedure find(x,y:integer);

    begin

    if (x=n) and (y=m) then inc(z)

    else

    begin

    if (a[x+1,y]=0) and (x+1

  • 0
    @ 2009-07-13 20:47:04

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    简单的DP,秒杀~

信息

ID
1121
难度
4
分类
动态规划 点击显示
标签
递交数
9572
已通过
3779
通过率
39%
被复制
23
上传者