讨论 / 10分求大牛找错,灰常感谢
woai9bansc 2011-11-05 09:06:00
点我顶贴 收藏 删除
program change;

var s,o,x:ansistring;

ls,lf,l,r,i,n,j,p:longint;

f:array [1..10000] of ansistring;

a,b:array [1..6] of ansistring;

la,lb:array [1..6] of longint;

pa:array [1..6,1..255] of longint;

p1:array [1..10000] of longint;

function nore:boolean;

var i:longint;

begin

nore:=true;

for i:=r downto 1 do if f[i]=x then exit(false);

end;

function ck:boolean;

var j1,k1,j,k:longint;

begin

j:=1;

repeat

j1:=j; k:=1;

while a[i,k]=f[l,j1] do begin inc(j1); inc(k); end;

if k>la[i] then begin p:=j; exit(true); end;

inc(j);

until j>lf;

ck:=false;

end;

begin

readln(s);

i:=pos(' ',s);

o:=copy(s,i+1,length(s)-i+1);

delete(s,i,length(s)-i+1);

ls:=length(s);

i:=0;

while not(eof) do

begin

inc(i);

readln(a[i]);

j:=pos(' ',a[i]);

b[i]:=copy(a[i],j+1,length(a[i])-j+1);

delete(a[i],j,length(a[i])-j+1);

la[i]:=length(a[i]);

lb[i]:=length(b[i]);

end;

n:=i;

l:=1; r:=1; f[r]:=s; p1[l]:=0;

while l<=r do

begin

lf:=length(f[l]);

for i:=1 to n do

begin

if (ck) then

begin

x:=copy(f[l],1,p-1)+b[i]+copy(f[l],p+la[i],lf-p-la[i]+1);

if nore then begin

inc(r);

p1[r]:=p1[l]+1;

if (x=o)and(p1[r]<=10) then

begin

writeln(p1[r]);

halt;

end

else if p1[r]>10 then begin writeln('NO ANSWER!'); halt; end;

f[r]:=x;

end;

end;

end;

inc(l);

end;

END.

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

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

测试结果3: 输出过少|用户输出数据少于标准输出的50%[标准输出10位|选手输出1位]

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

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

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

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

测试结果8: 输出过少|用户输出数据少于标准输出的50%[标准输出10位|选手输出1位]

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

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

求大牛指点!

#1 woai9bansc@2011-11-05 09:06:00
回复 删除
回复 楼主woai9bansc 的帖子

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

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

测试结果3: 通过本测试点|有效耗时62ms

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

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

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

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

测试结果8: 通过本测试点|有效耗时62ms

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

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

提交代码: view sourceprint?01.program change;

program change;

var s,o,x:ansistring;

ls,lf,l,r,i,n,j,p:longint;

f:array [1..10000] of ansistring;

a,b:array [1..6] of ansistring;

la,lb:array [1..6] of longint;

pa:array [1..6,1..100000] of longint;

p1:array [1..100000] of longint;

function nore:boolean;

var i:longint;

begin

nore:=true;

for i:=r downto 1 do if f[i]=x then exit(false);

end;

procedure kmp1;

var k,j:longint;

begin

k:=0;

pa[i,1]:=0;

for j:=2 to la[i] do

begin

while (k>0)and(a[i,k+1]<>a[i,j]) do k:=pa[i,k];

if a[i,k+1]=a[i,j] then k:=k+1;

pa[i,j]:=k;

end;

end;

function ck:boolean;

var q,j:longint;

begin

q:=0; ck:=false;

for j:=1 to lf do

begin

while (q>0)and(a[i,q+1]<>f[l,j]) do q:=pa[i,q];

if a[i,q+1]=f[l,j] then q:=q+1;

if (q=la[i]) then begin p:=j-la[i]+1; exit(true); end;

end;

end;

begin

fillchar(la,sizeof(la),0);

fillchar(lb,sizeof(lb),0);

fillchar(pa,sizeof(pa),0);

fillchar(p1,sizeof(p1),0);

readln(s);

i:=pos(' ',s);

o:=copy(s,i+1,length(s)-i+1);

delete(s,i,length(s)-i+1);

ls:=length(s);

i:=0;

while not(eof) do

begin

inc(i);

readln(a[i]);

j:=pos(' ',a[i]);

b[i]:=copy(a[i],j+1,length(a[i])-j+1);

delete(a[i],j,length(a[i])-j+1);

la[i]:=length(a[i]);

lb[i]:=length(b[i]);

end;

n:=i;

l:=1; r:=1; f[r]:=s; p1[l]:=0;

for i:=1 to n do kmp1;

while l<=r do

begin

lf:=length(f[l]);

for i:=1 to n do

begin

if (ck) then

begin

x:=copy(f[l],1,p-1)+b[i]+copy(f[l],p+la[i],lf-p-la[i]+1);

if nore then begin

inc(r);

p1[r]:=p1[l]+1;

if (x=o)and(p1[r]<=10) then

begin

writeln(p1[r]);

halt;

end

else if p1[r]>10 then begin writeln('NO ANSWER!'); halt; end;

f[r]:=x;

end;

end;

end;

inc(l);

end;

writeln('NO ANSWER!');

END.

改了以后还只有80 —--

查看更多回复
提交回复