207 条题解

  • 0
    @ 2009-10-28 14:40:56

    九个for的故事流传很久了……

    个人认为算法是正确的 但是一般不可能秒杀 因为实际处理的语句数还是挺多的

    每个操作只有0..3 四种可能,故全部情况数为4^9=262144,若有解,则必然在这些方案之中

    设操作总数sum=a+b+c+d+e+f+g+h+i 考虑到操作要最短 则sum必须小于当前已记录的可行最小操作数(设为min)。又因为一开始我们就已经按照字典序搜索可行解,所以当sum=min时,新方案的字典序必增大,故舍去新方案

    综上 若sum>=min 就不保存方案

    于是乎保存下来的方案就是正确答案了

    PS:

    但是对于这个题目,似乎找到的第一个可行方案就是正确答案(我试过),大概是因为变换规则太弱或者数据太弱了……所以出现了很多用“九个for”秒杀的人……

  • 0
    @ 2009-10-27 21:24:09

    program p1016;

    const

    r:array[1..9,1..9]of integer=

    ((1,1,0,1,1,0,0,0,0),

    (1,1,1,0,0,0,0,0,0),

    (0,1,1,0,1,1,0,0,0),

    (1,0,0,1,0,0,1,0,0),

    (0,1,0,1,1,1,0,1,0),

    (0,0,1,0,0,1,0,0,1),

    (0,0,0,1,1,0,1,1,0),

    (0,0,0,0,0,0,1,1,1),

    (0,0,0,0,1,1,0,1,1));

    var

    i:longint;

    ans,a:array[1..9]of longint;

    function yes:boolean;

    var i:longint;

    begin

    yes:=true;

    for i:=1 to 9 do if (a[i]mod 4)0 then exit(false);

    end;

    procedure use(x:longint);

    var

    i:longint;

    begin

    if x>9 then exit;

    for i:=1 to 9 do a[i]:=a[i]+r[x,i];

    end;

    procedure disuse(x:longint);

    var

    i:longint;

    begin

    if x>9 then exit;

    for i:=1 to 9 do a[i]:=a[i]-r[x,i];

    end;

    procedure handle(x,depth:integer);

    var

    i,j:longint;

    begin

    if x>9 then exit;

    if depth>3 then exit;

    if yes() then begin

    for i:=1 to 9 do

    for j:=1 to ans[i] do write(i,' ');

    exit;

    end;

    begin handle(x+1,0); end;

    begin use(x);inc(ans[x]);handle(x,depth+1); disuse(x);dec(ans[x]);end;

    end;

    begin

    for i:=1 to 9 do

    read(a[i]);

    handle(1,0);

    end.

  • 0
    @ 2009-10-25 08:49:26

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    program P1016;

    const

    ctrl:array[1..9,1..9]of integer=((3,3,3,3,3,2,3,2,0),

    (2,3,2,3,2,3,1,0,1),

    (3,3,3,2,3,3,0,2,3),

    (2,3,1,3,2,0,2,3,1),

    (2,3,2,3,1,3,2,3,2),

    (1,3,2,0,2,3,1,3,2),

    (3,2,0,3,3,2,3,3,3),

    (1,0,1,3,2,3,2,3,2),

    (0,2,3,2,3,3,3,3,3));

    var

    i,j,k,n:integer;

    a,time:array[1..9]of integer;

    ans:array[1..27]of integer;

    begin

    for i:=1 to 3 do

    begin

    for j:=1 to 3 do

    read(a[(i-1)*3+j]);

    readln;

    end;

    for i:=1 to 9 do

    time[i]:=0;

    for i:=1 to 9 do

    for j:=1 to (4-a[i])mod 4 do

    for k:=1 to 9 do

    time[k]:=(time[k]+ctrl)mod 4;

    n:=0;

    for i:=1 to 9 do

    for j:=1 to time[i] do

    begin

    n:=n+1;

    ans[n]:=i;

    end;

    for i:=1 to n-1 do

    write(ans[i],' ');

    writeln(ans[n]);

    end.

    USACO题解的打表算法

  • 0
    @ 2009-10-25 10:52:35

    dfs

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-10-23 20:33:01

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-10-12 18:08:00

    尚未完成的程序

    program p1016;

    var a:array[1..9] of integer;

    i:integer;

    function pd(a):boolean;

    var j:integer;

    begin

    pd:=true;

    for j:=1 to 9 do

    if (a[i]0) then pd:=false;

    end;

    procedure sc

    procedure search(k:integer);

    begin

    if pd(a) then begin sc; exit; end;

    for

    end;

    begin

    for i:=1 to 9 do

    begin

    read(a[i]);

    if a[i]=3 then a[i]:=1

    else if a[i]=1 then a[i]:=3;

    end;

    searth(1);

    end.

  • 0
    @ 2009-10-12 09:33:15

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    写了个暴搜居然秒杀了...

    program cl(input,output);

    const ch:array[1..9,1..9]of longint=((1,1,0,1,1,0,0,0,0),

    (1,1,1,0,0,0,0,0,0),

    (0,1,1,0,1,1,0,0,0),

    (1,0,0,1,0,0,1,0,0),

    (0,1,0,1,1,1,0,1,0),

    (0,0,1,0,0,1,0,0,1),

    (0,0,0,1,1,0,1,1,0),

    (0,0,0,0,0,0,1,1,1),

    (0,0,0,0,1,1,0,1,1));

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

    f:array[1..2,1..9]of longint;

    i:longint;

    procedure writedata;

    var j,l:longint;

    begin

    for j:=1 to 9 do

    for l:=1 to f[2,j] do

    write(j,' ');

    writeln;

    halt;

    end;

    procedure main(k:longint);

    var j,l:longint;

    p:boolean;

    begin

    p:=true;

    for j:=1 to 9 do

    if f[1,j]0 then

    begin

    p:=false;

    break;

    end;

    if p then writedata;

    if k=0 then exit;

    for j:=3 downto 0 do//这个地方必须倒搜

    begin

    for l:=1 to 9 do

    if ch[k,l]=1 then f[1,l]:=(f[1,l]+j)mod 4;

    f[2,k]:=j;

    main(k-1);

    for l:=1 to 9 do

    if ch[k,l]=1 then f[1,l]:=(f[1,l]+4-j) mod 4;

    end;

    end;

    begin

    for i:=1 to 9 do

    begin

    read(a[i]);

    f[1,i]:=a[i];

    end;

    main(9);//这个地方也是,必须倒搜

    end.

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

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

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

    因为数组开小了,结果WA了一个40分,然后开大点就AC了。。。。。。。。。。。。

    所以结论是:开数组一定要大点

  • 0
    @ 2009-10-09 10:47:27

    BFS王道 1A

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    就是写的太恶心了 这么长 运行也恶心 用那么长时间

    var

    sta,obj:longint;

    line:array[1..262144]of record

    t:longint;

    end;

    state:array[0..262143,0..100]of integer;

    st,ed:longint;

    i,j,k:longint;

    p:array[1..9]of longint;

    procedure add(n:longint);

    begin inc(p[n]); if p[n]=4 then p[n]:=0; end;

    procedure min(n:longint);

    begin dec(p[n]); if p[n]=-1 then p[n]:=3; end;

    procedure make(n:longint);

    var

    t,r,l:longint;

    begin

    fillchar(p,sizeof(p),0); l:=0;

    while n>0 do

    begin

    inc(l);

    r:=n mod 4;

    n:=n shr 2;

    p[l]:=r;

    end;

    end;

    function get:longint;

    var

    t,r,l:longint;

    begin

    get:=0;

    for i:=9 downto 1 do

    begin

    get:=get shl 2;

    get:=get+p[i];

    end;

    end;

    function check(n,t,m:longint):boolean;

    var

    y:longint;

    begin

    check:=false;

    if state[n][0]+1state[m][y] then exit(false);

    if t>state[n][y+1] then exit(false);

    end;

    end;

    begin

    for i:=1 to 9 do read(p[i]);

    sta:=get;obj:=0;

    fillchar(state,sizeof(state),100);

    state[sta][0]:=0;

    st:=1;ed:=2;k:=0; line[1].t:=sta;

    while k=0 do

    begin

    if line[st].t=0 then

    begin

    break;

    end;

    make(line[st].t);

    add(1);add(2);add(4);add(5);

    j:=get;

    if check(line[st].t,1,j)=true then

    begin

    state[j]:=state[line[st].t];

    inc(state[j][0]);

    state[j][state[j][0]]:=1;

    line[ed].t:=j;

    inc(ed);if ed=262144 then ed:=1;

    end;

    min(1);min(2);min(4);min(5);

    add(1);add(2);add(3);

    j:=get;

    if check(line[st].t,2,j)=true then

    begin

    state[j]:=state[line[st].t];

    inc(state[j][0]);

    state[j][state[j][0]]:=2;

    line[ed].t:=j;

    inc(ed);if ed=262144 then ed:=1;

    end;

    min(1);min(2);min(3);

    add(2);add(3);add(5);add(6);

    j:=get;

    if check(line[st].t,3,j)=true then

    begin

    state[j]:=state[line[st].t];

    inc(state[j][0]);

    state[j][state[j][0]]:=3;

    line[ed].t:=j;

    inc(ed);if ed=262144 then ed:=1;

    end;

    min(2);min(3);min(5);min(6);

    add(1);add(4);add(7);

    j:=get;

    if check(line[st].t,4,j)=true then

    begin

    state[j]:=state[line[st].t];

    inc(state[j][0]);

    state[j][state[j][0]]:=4;

    line[ed].t:=j;

    inc(ed);if ed=262144 then ed:=1;

    end;

    min(1);min(4);min(7);

    add(2);add(4);add(5);add(6);add(8);

    j:=get;

    if check(line[st].t,5,j)=true then

    begin

    state[j]:=state[line[st].t];

    inc(state[j][0]);

    state[j][state[j][0]]:=5;

    line[ed].t:=j;

    inc(ed);if ed=262144 then ed:=1;

    end;

    min(2);min(4);min(5);min(6);min(8);

    add(3);add(6);add(9);

    j:=get;

    if check(line[st].t,6,j)=true then

    begin

    state[j]:=state[line[st].t];

    inc(state[j][0]);

    state[j][state[j][0]]:=6;

    line[ed].t:=j;

    inc(ed);if ed=262144 then ed:=1;

    end;

    min(3);min(6);min(9);

    add(4);add(5);add(7);add(8);

    j:=get;

    if check(line[st].t,7,j)=true then

    begin

    state[j]:=state[line[st].t];

    inc(state[j][0]);

    state[j][state[j][0]]:=7;

    line[ed].t:=j;

    inc(ed);if ed=262144 then ed:=1;

    end;

    min(4);min(5);min(7);min(8);

    add(7);add(8);add(9);

    j:=get;

    if check(line[st].t,8,j)=true then

    begin

    state[j]:=state[line[st].t];

    inc(state[j][0]);

    state[j][state[j][0]]:=8;

    line[ed].t:=j;

    inc(ed);if ed=262144 then ed:=1;

    end;

    min(7);min(8);min(9);

    add(5);add(6);add(8);add(9);

    j:=get;

    if check(line[st].t,9,j)=true then

    begin

    state[j]:=state[line[st].t];

    inc(state[j][0]);

    state[j][state[j][0]]:=9;

    line[ed].t:=j;

    inc(ed);if ed=262144 then ed:=1;

    end;

    min(5);min(6);min(8);min(9);

    inc(st);if st=262144 then st:=1;

    end;

    for i:=1 to state[0][0] do

    begin

    if istate[0][0] then write(state[0][i],' ')

    else writeln(state[0][i]);

    end;

    end.

  • 0
    @ 2009-10-08 08:03:57

    program su_he(input,output);

    {一个常量数组,用来记录每组方案,记录时要将方案中的字符转化成数字,a表示每组的方案个数}

    const

    a:array[1..9,0..9]of integer=((4,1,2,4,5,0,0,0,0,0),

    (3,1,2,3,0,0,0,0,0,0),

    (4,2,3,5,6,0,0,0,0,0),

    (3,1,4,7,0,0,0,0,0,0),

    (5,2,4,5,6,8,0,0,0,0),

    (3,3,6,9,0,0,0,0,0,0),

    (4,4,5,7,8,0,0,0,0,0),

    (3,7,8,9,0,0,0,0,0,0),

    (4,5,6,8,9,0,0,0,0,0));

    type

    ppt=array[1..9]of integer;

    var

    f,b:ppt;

    i,j,k:integer;

    function ok(f:ppt):boolean;

    var

    i,j:integer;

    begin

    ok:=true;

    for i:=1 to 9 do

    if f[i] mod 40 then exit(false); {如果f中的任何一个数不满足条件,则函数为零}

    end;

    procedure out(b:ppt);

    var

    i,j,k:integer;

    s:string;

    begin

    s:=''; {用字符串记录结果,方便输出}

    for i:=1 to 9 do

    for j:=1 to b[i] do

    s:=s+chr(i+48)+' '; {一个方案使用几次就输出几次}

    delete(s,length(s),1); {去掉最后的括号}

    writeln(s); {输出}

    end;

    procedure try(n:integer;f,b:ppt);

    var

    i,j,k:integer;

    begin

    if n=10 then begin

    if ok(f) then out(b);

    exit; {如果满足条件,那么输出}

    end;

    for i:=0 to 3 do {每一个方案最多只能用三次,再加上不用的情况,0~3}

    begin

    b[n]:=i; {b数组记录使用次数}

    for j:=1 to a[n,0] do

    inc(f[a[n,j]],i); {进行变化,即每数加1(先不必进行f[a[n,i]]超过4时的处理}

    try(n+1,f,b); {递归下一个}

    for j:=1 to a[n,0] do

    dec(f[a[n,j]],i); {回溯}

    end;

    end;

    begin

    for i:=1 to 9 do

    begin

    read(f[i]);

    if i mod 3=0 then readln;

    end;{按矩阵读数}

    try(1,f,b);{开始}

    end.

  • 0
    @ 2009-10-07 16:43:24

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    ___|\__|\__|\__|\__|\__|\__|\__|\__|\__|\__|我的名字叫分界线\__|\__|\__|\__|\__|\_|_

    穷举...

    话说我怎么不清不白的过的我都不知道...

    ___|\
    __|\__|\__|\__|\__|\__|\__|\__|\__|\_我的名字叫分界线\__|\__|\__|\__|\__|\___|__

    #include

    int main()

    {

    int c[9];

    int cc[9];

    int a;

    int m[10];

    int y=0;

    int ml=0;

    for(a=0;a

  • 0
    @ 2009-10-04 20:28:53

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    usaco 的 经过一番调整

    编译通过...

    ├ 测试数据 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-04 19:03:46

    编译通过...

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

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

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

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

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

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

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

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

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

     ├ 错误行输出 ...7 9...

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

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

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

    const act:array[1..9]of string[5]=('ABDE','ABC','BCEF','ADG','BDEFH','CFI','DEGH','GHI','EFHI');

    maxn=300000;

    type arr=array[1..9]of integer;

    var i,j,f,r,t,o,p:longint;

    s:string; ff:boolean;

    q:array[1..maxn]of arr;

    link:array[1..maxn]of longint;

    a:array[0..maxn]of integer;

    flag:array[0..maxn]of boolean;

    x,y:arr;

    procedure print(x:longint);

    begin

    if link[x]>0 then

    begin

    print(link[x]);

    write(a[x],' ');

    end;

    end;

    begin

    t:=0;

    for i:=1 to 9 do

    begin read(o); q[1,i]:=o; t:=t*4+o; end;

    for i:=0 to maxn do flag[i]:=true;

    if t=0 then begin writeln(' '); exit; end;

    flag[t]:=false; link[1]:=0;

    f:=0; r:=1; ff:=true;

    a[1]:=1;

    while (f

  • 0
    @ 2009-09-27 15:51:10

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    从小到大[1..9]的变法搜

    从少到多[1..3次]的搜

    回溯直到全是0[mod 4]搜到第一次就输出即可

  • 0
    @ 2009-09-27 14:02:25

    编译通过...

    ├ 测试数据 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-02 09:56:54

    这个题太猥亵了

    本来没怎么写过广搜,兴奋地拿来练手,结果却是打击……

    如果写正宗的广搜,全部tle:如下:

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    const

    move:array[1..9,1..9]of longint=

    ((1,1,0,1,1,0,0,0,0),(1,1,1,0,0,0,0,0,0),

    (0,1,1,0,1,1,0,0,0),(1,0,0,1,0,0,1,0,0),

    (0,1,0,1,1,1,0,1,0),(0,0,1,0,0,1,0,0,1),

    (0,0,0,1,1,0,1,1,0),(0,0,0,0,0,0,1,1,1),

    (0,0,0,0,1,1,0,1,1));

    var

    a:array[1..7000,1..9]of longint;

    h,t,i,j,k:longint;

    b:array[1..9]of longint;

    road:array[1..7000,1..2]of longint;

    function check:boolean;

    var i1,j1:longint;d:boolean;

    begin

    for i1:=1 to t do

    begin d:=true;

    for j1:=1 to 9 do

    begin d:=d and(a[i1,j1]=b[j1]);if not(d)then break;end;

    if d then exit(true);

    end;

    exit(false);

    end;

    function check2:boolean;

    var i1:longint;d:boolean;

    begin d:=true;

    for i1:=1 to 9 do

    d:=d and(a[t,i1]=0);

    if d then exit(true);exit(false);

    end;

    procedure print(i:longint);

    begin

    if i=1 then exit;

    print(road);

    write(road,' ');

    end;

    begin

    for i:=1 to 9 do read(a[1,i]);

    h:=0;t:=1;

    while h

  • 0
    @ 2009-09-19 21:28:48

    program su_he(input,output);

    {一个常量数组,用来记录每组方案,记录时要将方案中的字符转化成数字,a表示每组的方案个数}

    const

    a:array[1..9,0..9]of integer=((4,1,2,4,5,0,0,0,0,0),

    (3,1,2,3,0,0,0,0,0,0),

    (4,2,3,5,6,0,0,0,0,0),

    (3,1,4,7,0,0,0,0,0,0),

    (5,2,4,5,6,8,0,0,0,0),

    (3,3,6,9,0,0,0,0,0,0),

    (4,4,5,7,8,0,0,0,0,0),

    (3,7,8,9,0,0,0,0,0,0),

    (4,5,6,8,9,0,0,0,0,0));

    type

    ppt=array[1..9]of integer;

    var

    f,b:ppt;

    i,j,k:integer;

    function ok(f:ppt):boolean;

    var

    i,j:integer;

    begin

    ok:=true;

    for i:=1 to 9 do

    if f[i] mod 40 then exit(false); {如果f中的任何一个数不满足条件,则函数为零}

    end;

    procedure out(b:ppt);

    var

    i,j,k:integer;

    s:string;

    begin

    s:=''; {用字符串记录结果,方便输出}

    for i:=1 to 9 do

    for j:=1 to b[i] do

    s:=s+chr(i+48)+' '; {一个方案使用几次就输出几次}

    delete(s,length(s),1); {去掉最后的括号}

    writeln(s); {输出}

    end;

    procedure try(n:integer;f,b:ppt);

    var

    i,j,k:integer;

    begin

    if n=10 then begin

    if ok(f) then out(b);

    exit; {如果满足条件,那么输出}

    end;

    for i:=0 to 3 do {每一个方案最多只能用三次,再加上不用的情况,0~3}

    begin

    b[n]:=i; {b数组记录使用次数}

    for j:=1 to a[n,0] do

    inc(f[a[n,j]],i); {进行变化,即每数加1(先不必进行f[a[n,i]]超过4时的处理}

    try(n+1,f,b); {递归下一个}

    for j:=1 to a[n,0] do

    dec(f[a[n,j]],i); {回溯}

    end;

    end;

    begin

    for i:=1 to 9 do

    begin

    read(f[i]);

    if i mod 3=0 then readln;

    end;{按矩阵读数}

    try(1,f,b);{开始}

    end.

  • 0
    @ 2009-09-19 10:58:19

    超级枚举……

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2009-09-19 00:59:08

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    搞笑,九重循环居然过啦。。。。

  • 0
    @ 2009-09-16 21:12:34

    ..强悍的九层循环....

    每个操作最多四次~~

    真的很强悍,,,虽然代码委琐了点...

信息

ID
1016
难度
5
分类
搜索 | 搜索与剪枝 点击显示
标签
递交数
4782
已通过
1601
通过率
33%
被复制
15
上传者