讨论 / 请哪位高手看一下哪错了!
zzqq2199 2012-07-30 00:59:00
点我顶贴 收藏 删除
状态: Unaccepted

测评机: Xeond[6]

得分: 80分

提交日期: 2012-7-30 13:59:00

有效耗时: 1329毫秒

测试结果1: 通过本测试点|有效耗时172ms

测试结果2: 通过本测试点|有效耗时172ms

测试结果3: 输出过长|用户输出数据超过标准输出两倍[标准输出10位|选手输出363位]

测试结果4: 通过本测试点|有效耗时157ms

测试结果5: 通过本测试点|有效耗时172ms

测试结果6: 通过本测试点|有效耗时156ms

测试结果7: 通过本测试点|有效耗时172ms

测试结果8: 输出过长|用户输出数据超过标准输出两倍[标准输出10位|选手输出363位]

测试结果9: 通过本测试点|有效耗时156ms

测试结果10: 通过本测试点|有效耗时172ms

思路:双向宽搜+hash判重

const zq=10007;

type pp=record

s :string;

x,y:longint;

end;

var

s1,s2,s:string;

x,i,j,k,c_rule:longint;

rule :array[1..6,1..2] of string;

hash :array[1..zq] of pp;

st :array[1..2,1..zq] of string;

head,tail :array[1..2] of longint;

function plus(var x:longint):longint;

begin

inc(x); if x>zq then x:=0;

end;

function jian(var x:longint):longint;

begin

dec(x); if x<0 then x:=zq;

end;

function num(s:string):longint;

var i:longint;

begin

num:=0;

for i:=1 to length(s) do

num:=num+ord(s[i])*10*i;

num:=num mod zq;

end;

procedure join(s:string; x,y:longint);

var n:longint;

begin

n:=num(s);

while ( hash[n].y <> 0 ) and ( hash[n].s <> s ) do

plus(n);

if hash[n].y = 0 then

begin

hash[n].s:=s;

hash[n].x:=x;

hash[n].y:=y;

exit;

end;

if hash[n].y=y then exit;

writeln(x+hash[n].x);

halt;

end;

procedure try(x:longint);

var

sc,sx,sd,sp,sp2,s:string;

i,j,tou,wei,p:longint;

begin

if x>5 then

begin

for i:=1 to tail[1] do writeln(st[1,i]);

writeln;

for i:=1 to tail[2] do writeln(st[2,i]);

writeln;

writeln('NO ANSWER!'); halt ;

end;

tou:=head[1]; wei:=tail[1]; head[1]:=tail[1]+1;

for i:=tou to wei do begin

s:=st[1,i];

for j:=1 to c_rule do begin

sc:='';

sx:=s;

sp:=rule[j,1];

sp2:=rule[j,2];

p:=pos(sp,sx);

while p>0 do

begin

sd:=sx;

delete(sd,p,length(sp));

insert(sp2,sd,p);

join(sc+sd,x,1);

inc(tail[1]);

st[1,tail[1]]:=sc+sd;

sc:=sc+copy(sx,1,p);

delete(sx,1,p);

p:=pos(sp,sx);

end;

end;

end;

tou:=head[2]; wei:=tail[2]; head[2]:=tail[2]+1;

for i:=tou to wei do begin

s:=st[2,i];

for j:=1 to c_rule do begin

sc:='';

sx:=s;

sp:=rule[j,2];

sp2:=rule[j,1];

p:=pos(sp,sx);

while p>0 do

begin

sd:=sx;

delete(sd,p,length(sp));

insert(sp2,sd,p);

join(sc+sd,x,2);

inc(tail[2]);

st[2,tail[2]]:=sc+sd;

sc:=sc+copy(sx,1,p);

delete(sx,1,p);

p:=pos(sp,sx);

end;

end;

end;

try(x+1);

end;

procedure init;

begin

readln(s2);

x:=pos(' ',s2);

s1:=copy(s2,1,x-1);

delete(s2,1,x);

while not eof do

begin

inc(c_rule);

readln(s);

x:=pos(' ',s);

rule[c_rule,1]:=copy(s,1,x-1);

delete(s,1,x);

rule[c_rule,2]:=s;

end;

head[1]:=1; head[2]:=1; tail[1]:=1; tail[2]:=1;

st[1,1]:=s1; st[2,1]:=s2;

join(s1,0,1); join(s2,0,2);

end;

begin

init;

try(1);

end.

#1 zzqq2199@2012-07-29 23:15:00
回复 删除
无语啊。。。

其实我知道哪儿错了

for i:=1 to tail[1] do writeln(st[1,i]);

writeln;

for i:=1 to tail[2] do writeln(st[2,i]);

writeln;

就多写了这几句

#2 王昱炜@2012-07-30 00:59:00
回复 删除
错的差一点

for i:=1 to tail[1] do writeln(st[1,i]);

writeln;

for i:=1 to tail[2] do writeln(st[2,i]);

writeln;

多写了这几句

查看更多回复
提交回复