题解

128 条题解

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

    program b_max;

    type

    gz=array[1..6,1..2]of string;

    ww=array[1..10000]of record

    now:string;

    step:longint;

    end;

    kkk=array[0..10000]of longint;

    var

    a:gz;

    dui1,dui2:ww;

    qishi,mubiao:string;

    i,j,n,k,lena:longint;

    data,h1,t1,m1,t2,h2,m2:longint;

    posi1,posi2:kkk;

    procedure fill;

    var s1,s2,s3:string;

    k:longint;

    begin

    readln(s1);

    k:=pos(' ',s1);

    qishi:=copy(s1,1,k-1);

    mubiao:=copy(s1,k+1,length(s1)-k);

    while not eof do

    begin

    readln(s1);

    k:=pos(' ',s1);

    inc(lena);

    a[lena,1]:=copy(s1,1,k-1);

    a[lena,2]:=copy(s1,k+1,length(s1)-k);

    end;

    h1:=1; t1:=1; m1:=1;

    h2:=1; t2:=1; m2:=1;

    dui1[t1].now:=qishi;

    dui2[t2].now:=mubiao;

    end;

    procedure search(var posi1:kkk;s1,s2:string);

    var i,j,l1,l2:longint;

    begin

    fillchar(posi1,sizeof(posi1),0);

    l1:=length(s1);

    l2:=length(s2);

    for i:=1 to l1 do

    if copy(s1,i,l2)=s2 then

    begin

    inc(posi1[0]);

    posi1[posi1[0]]:=i;

    end;

    end;

    procedure change1(x,y:longint);

    var i,j:longint;

    s1,s2:string;

    begin

    s1:=copy(dui1.now,1,y-1);

    s2:=copy(dui1.now,y+length(a[x,1]),length(dui1.now)-y-length(a[x,1])+1);

    inc(t1);

    dui1[t1].now:=s1+a[x,2]+s2;

    dui1[t1].step:=dui1.step+1;

    end;

    procedure change2(x,y:longint);

    var i,j:longint;

    s1,s2:string;

    begin

    s1:=copy(dui2.now,1,y-1);

    s2:=copy(dui2.now,y+length(a[x,2]),length(dui2.now)-y-length(a[x,2])+1);

    inc(t2);

    dui2[t2].now:=s1+a[x,1]+s2;

    dui2[t2].step:=dui2.step+1;

    end;

    function check1:boolean;

    var i:longint;

    begin

    for i:=t2 downto 1 do

    if dui2[i].now=dui1[t1].now then

    begin

    data:=dui2[i].step;

    exit(true);

    end;

    exit(False);

    end;

    function check2:boolean;

    var i:longint;

    begin

    for i:=t1 downto 1 do

    if dui1[i].now=dui2[t2].now then

    begin

    data:=dui1[i].step;

    exit(true);

    end;

    exit(false);

    end;

    begin

    fill;

    repeat

    while h1m1+1 do

    begin

    for i:=1 to lena do

    begin

    search(posi1,dui1.now,a

  • 0
    @ 2009-07-16 14:33:22

    用双向BFS 0ms

  • 0
    @ 2009-07-08 15:31:38

    var

    a,b:string;

    n,answer:integer;

    len:array[0..5]of integer;

    s1,s2:array[0..5]of string;

    procedure reads(var s1,s2:string);

    var

    s:string;

    begin

    readln(s);

    s1:=copy(s,1,pos(' ',s)-1);

    s2:=copy(s,pos(' ',s)+1,length(s)-pos(' ',s));

    end;

    function max(a,b:integer):integer;

    begin

    if a>b then max:=a

    else max:=b;

    end;

    procedure search(depth:integer;s:string;last:integer);

    var

    i,j,l:integer;

    begin

    if (depth=0) then

    begin

    if (s=b) then

    begin

    writeln(answer);

    halt;

    end;

    exit;

    end;

    l:=length(s);

    dec(depth);

    for i:=1 to n do

    for j:=max(1,last-len[i]+1) to l-len[i]+1 do

    if (copy(s,j,len[i])=s1[i]) then

    search(depth,copy(s,1,j-1)+s2[i]+copy(s,j+len[i],l-j-len[i]+1),j);

    end;

    begin

    reads(a,b);

    while (not seekeof) do

    begin

    inc(n);

    reads(s1[n],s2[n]);

    len[n]:=length(s1[n]);

    end;

    for answer:=1 to 10 do

    search(answer,a,1);

    writeln('NO ANSWER!');

    end.

  • 0
    @ 2009-05-16 15:56:14

    编译通过...

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

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

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

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

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

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

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

    广搜 + 自己乱编的字符Hash

    哪位大牛给个方便的字符Hash?

  • 0
    @ 2009-05-03 10:19:53

    编译通过...

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

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

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

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

    ├ 测试数据 05:答案错误...程序输出比正确答案长

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

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

    虽然一直没过 但学习了双搜感觉收获很大

  • 0
    @ 2009-04-25 13:05:00

    好久没来这里做题了,今天突然想起了来做一哈,没想到啊!题交了一看,评测机都W了一长串了!

  • 0
    @ 2009-03-03 19:13:17

    编译通过...

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

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

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

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

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

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

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

  • 0
    @ 2009-02-05 23:10:44

    双向bfs,左右两边的规则真好是反过来的,千万别写错了

  • 0
    @ 2008-12-20 23:06:03

    编译通过...

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

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

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

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

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

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

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

    简单的分支定界

  • 0
    @ 2008-11-12 10:27:05

    双搜……

  • 0
    @ 2008-11-12 01:22:01

    BST 无敌。。

  • 0
    @ 2008-11-11 08:31:36

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

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

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

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

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

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

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

    双搜,不用hash.

  • 0
    @ 2008-11-08 09:39:31

    编译通过...

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

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

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

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

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

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

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

    \\\\\\\\\\\\\\\\\\\\\\\

    --不用检索树,也不用ELF HASH。。。。用2分排序树的 单向BFS就可以了。。。。。

  • 0
    @ 2008-11-07 21:59:27

    迭代加深+哈西判重就可以过了,而且程序写的很舒服。

    我一直觉得双向广搜写的很难受……

  • 0
    @ 2008-11-07 09:54:37

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

    BST判重=0ms

  • 0
    @ 2008-11-05 15:16:14

    不会2向广搜 但是貌似dfs就行

    跟luyifan的代码差不多

  • 0
    @ 2008-11-04 21:09:47

    字符串处理真郁闷..

  • 0
    @ 2008-11-04 20:07:59

    trie+单向BFS=AC

    注意,任意子串都可变换!

  • 0
    @ 2008-10-29 15:31:48

    ID-DFS可以过。

    不过最后两个点对于ID-DFS有点Trik

    1.倒数第二个会不断的把串加长。

    开小了的话会rte...可以判一下长度

    2.最后一个....耗时较大。

    如果为了倒数第二个点把串开大的话,memset容易搞超时。

    注意适当权衡一下。

  • 0
    @ 2008-10-27 20:01:39

    不知道什么叫hash

    其实刚知道什么叫广搜

    不过还是过了

    第120道题,一遍AC

    庆祝一下

信息

ID
1124
难度
7
分类
搜索 | 搜索与剪枝 点击显示
标签
递交数
3886
已通过
784
通过率
20%
被复制
14
上传者