题解

83 条题解

  • 0
    @ 2009-09-19 17:09:01

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    现场生成一张40MB的表(二进制),然后比对。

  • 0
    @ 2009-09-18 14:11:41

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    啊哈哈哈看完Matrix67大牛的位运算教程写这个东西就是快

    大家可以看这里

    http://www.matrix67.com/blog/archives/122

    把那个N皇后的例子看明白了这题就很弱智了

    贴个小小的主过程

    function pd:integer; //模拟判断剩下4行能否全亮并计算按开关的次数

    var i,x,z,y,sum:integer;

    begin

    b:=a;

    sum:=0;

    for i:=1 to 4 do

    begin

    while b[i]5 then ans:=min(ans,pd+sum)

    else

    begin

    work(i+1,sum);

    x:=1 shl(i-1);

    if i=1 then y:=3

    else y:=(7 shl(i-2)) and 31;

    a[1]:=a[1] xor y;

    a[2]:=a[2] xor x;

    work(i+1,sum+1);

    a[1]:=a[1] xor y;

    a[2]:=a[2] xor x;

    end;

    end;

  • 0
    @ 2009-09-15 15:16:26

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    好恒定。。。。

  • 0
    @ 2009-09-02 20:07:12

    编译通过...

    ├ 测试数据 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-02 17:47:36

    反向DFS……

    Debug一个下午…………

  • 0
    @ 2009-09-02 08:14:46

    DFS加剪枝加位运算

    const allone=33554431;

    type

    point=^node;

    node=record

    number,steps:longint;

    next:point;

    end;

    var

    bemod,min,i,j,n,k,t,g,code:longint;

    hash:array[0..50000] of point;

    c:char;

    function update(i:longint; now:longint):longint;

    begin

    now:=now xor 1 shl (i-1);

    if ((i-1) mod 5)0 then now:=now xor (1 shl (i-2));

    if ((i+1) mod 5)1 then now:=now xor (1 shl i);

    if i5 then now:=now xor (1 shl (i-6));

    update:=now;

    end;

    procedure peset(d,step,now:longint);

    var

    ii, tt,i,j,previous:longint;

    pp,p:point;

    done:boolean;

    begin

    if step>7 then exit;

    pp:=hash[now mod bemod];

    while pp^.nextnil do

    begin

    pp:=pp^.next;

    if pp^.number=now then

    begin

    if step-1

  • 0
    @ 2009-08-28 20:16:04

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    写丑了,没MS

    var i,j,xx,yy,n,k,ii,x:longint;

    p:char;

    ha,num,f:array[0..1000000]of longint;

    function hash(x:longint):longint;

    var j:longint;

    begin

    j:=x mod 1000000;

    while (ha[j]-1)and(ha[j]x) do j:=(j+1)mod 1000000;

    exit(j);

    end;

    begin

    fillchar(ha,sizeof(ha),\(ff);
    fillchar(num,sizeof(num),\)ff);

    f[1]:=33554431;

    ha[hash(33554431)]:=33554431;

    num[hash(f[1])]:=0;

    i:=0;

    j:=1;

    while ij do

    begin

    // if j>900000 then break;

    i:=i+1;

    while (num[hash(f[i])]>=6)and(ij then break;

    {11000

    10000

    00000

    00000

    00000}

    yy:=f[i] xor 25690112;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {11100

    01000

    00000

    00000

    00000}

    yy:=f[i] xor 29622272 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {01110

    00100

    00000

    00000

    00000}

    yy:=f[i] xor 14811136 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00111

    00010

    00000

    00000

    00000}

    yy:=f[i] xor 7405568 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00011

    00001

    00000

    00000

    00000}

    yy:=f[i] xor 3178496 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {10000

    11000

    10000

    00000

    00000}

    yy:=f[i] xor 17580032 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {01000

    11100

    01000

    00000

    00000}

    yy:=f[i] xor 9314304 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00100

    01110

    00100

    00000

    00000}

    yy:=f[i] xor 4657152 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00010

    00111

    00010

    00000

    00000}

    yy:=f[i] xor 2328576 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00001

    00011

    00001

    00000

    00000}

    yy:=f[i] xor 1147904 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    10000

    11000

    10000

    00000}

    yy:=f[i] xor 549376 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    01000

    11100

    01000

    00000}

    yy:=f[i] xor 291072 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00100

    01110

    00100

    00000}

    yy:=f[i] xor 145536 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00010

    00111

    00010

    00000}

    yy:=f[i] xor 72768 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00001

    00011

    00001

    00000}

    yy:=f[i] xor 35872 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    10000

    11000

    10000}

    yy:=f[i] xor 17168 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    01000

    11100

    01000}

    yy:=f[i] xor 9096 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    00100

    01110

    00100}

    yy:=f[i] xor 4548 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    00010

    00111

    00010}

    yy:=f[i] xor 2274 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    00001

    00011

    00001}

    yy:=f[i] xor 1121 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    00000

    10000

    11000}

    yy:=f[i] xor 536 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    00000

    01000

    11100}

    yy:=f[i] xor 284 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    00000

    00100

    01110}

    yy:=f[i] xor 142 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    00000

    00010

    00111}

    yy:=f[i] xor 71 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    {00000

    00000

    00000

    00001

    00011}

    yy:=f[i] xor 35 ;

    if ha[hash(yy)]=-1 then

    begin

    j:=j+1;

    ha[hash(yy)]:=yy;

    num[hash(yy)]:=num[hash(f[i])]+1;

    f[j]:=yy;

    end;

    end;

    readln(n);

    for ii:=1 to n do

    begin

    x:=0;

    for i:=5 downto 1 do

    begin

    for j:=5 downto 1 do

    begin

    read(p);

    if p='1' then

    begin

    x:=x+1 shl ((i-1)*5+j-1)

    end;

    end;

    readln;

    end;

    writeln(num[hash(x)]);

    readln;

    end;

    end.

    %>_

  • 0
    @ 2009-08-26 16:20:32

    位运算果然厉害

  • 0
    @ 2009-08-22 15:25:47

    反向搜索=AC

  • 0
    @ 2009-08-12 14:42:38

    强大的位运算

  • 0
    @ 2009-08-05 20:15:55

    如对本题有疑问可以参看我的题解:http://xujieqi.blog.hexun.com/35722312_d.html

  • 0
    @ 2009-07-26 20:08:58

    用5重循环枚举第一行的操作......

    然后再枚举以下5行的状态

    多谢txx和hsh大牛的指教

  • 0
    @ 2009-07-26 16:56:26

    多谢Matrix67大牛结题报告

  • 0
    @ 2009-07-22 12:03:31

    XOR方程解,自由元枚举

  • 0
    @ 2009-07-09 19:05:36

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    真慢

  • 0
    @ 2009-07-09 17:56:38

    program switch;

    const bp=3214567;

    type pointer=^rec;

    rec=record

    v:longint;

    step:integer;

    next:pointer;

    end;

    var total:longint;

    hash:array[0..bp-1] of pointer;

    q:array[1..400000] of rec;

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

    p:pointer;

    function find(a:longint; step:integer):boolean;

    var now:pointer;

    begin

    now:=hash[a mod bp];

    while now nil do

    begin

    if now^.v=a then exit(true);

    now:=now^.next;

    end;

    new(now);

    now^.v:=a;

    now^.step:=step;

    now^.next:=hash[a mod bp];

    hash[a mod bp]:=now;

    total:=total+1;

    exit(false);

    end;

    function update(a:longint; p:integer):longint;

    begin

    a:=a xor (1 shl p);

    if (p mod 5)0 then a:=a xor (1 shl (p-1));

    if ((p+1) mod 5)0 then a:=a xor (1 shl (p+1));

    if p4 then a:=a xor (1 shl (p-5));

    exit(a);

    end;

    procedure run;

    var head:longint=0;

    open:longint=1;

    p:integer;

    begin

    find((1 shl 25)-1,0);

    q[1].v:=(1 shl 25)-1;

    q[1].step:=0;

    repeat

    inc(head);

    for p:=0 to 24 do

    if ((not find(update(q[head].v,p),q[head].step+1)) and (q[head].step+1=open;

    end;

    begin

    readln(n);

    run;

    for l:=1 to n do

    begin

    m:=0;

    for i:=1 to 5 do

    begin

    for j:=1 to 5 do

    begin

    read(k);

    m:=m*2+k*2;

    end;

    readln;

    end;

    if hash[m mod bp]=nil then writeln(-1)

    else

    begin

    p:=hash[m mod bp];

    while ((p^.nextnil) or (p^.v=m)) do

    if p^.v=m then writeln(p^.step) else writeln(-1);

    end;

    end;

    end.

  • 0
    @ 2009-07-01 19:18:44

    这题我们今年省选考的范围很大,要高斯消元。

    我很弱,我不会

  • 0
    @ 2009-06-29 20:55:24

    这道题目似乎可以用高斯消元吧。。。

  • 0
    @ 2009-06-09 14:54:07

    强烈支持位运算!!!!!!!!!!

    强烈支持matrix67!!!!!!!!!!

  • 0
    @ 2008-11-23 10:31:06

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    初识位运算,强极了,棒极了!

信息

ID
1197
难度
6
分类
搜索 点击显示
标签
(无)
递交数
1684
已通过
508
通过率
30%
被复制
6
上传者