讨论 / 大神看看哪错了啊,为啥老不能AC啊,第5组和第10组
lymlyj 2013-10-25 00:57:00
点我顶贴 收藏 删除
program lym63;

type think=record

x,y:string;

end;

var a,b,s:string;

k:longint;

max:longint;

f:array[0..1,1..1000] of think;

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

father:array[0..1,1..1000] of longint;

c:array[0..1,1..1000] of string;

procedure init;

var i,p:longint;

begin

k:=0;

readln(s);

p:=pos(' ',s);

a:=copy(s,1,p-1);

b:=copy(s,p+1,length(s)-p);

while not eof do

begin

readln(s);

p:=pos(' ',s);

inc(k);

f[0,k].x:=copy(s,1,p-1);

f[0,k].y:=copy(s,p+1,length(s)-p);

f[1,k].y:=copy(s,1,p-1);

f[1,k].x:=copy(s,p+1,length(s)-p);

end;

end;

function chong(t,p:longint):boolean;

var i:longint;

begin

chong:=false;

for i:=1 to t-1 do

if c[p,i]=c[p,t] then exit(true);

end;

procedure ok(p:integer);

var i,j:longint;

begin

if p=0 then

for i:=tail[1] downto 1 do

if c[1,i]=c[0,tail[0]] then

if father[1,i]+father[0,tail[0]]<=10 then begin writeln(father[1,i]+father[0,tail[0]]);halt;end

else begin writeln('NO ANSWER!');halt;end;

if p=1 then

for j:=tail[0] downto 1 do

if c[0,j]=c[1,tail[1]] then

if father[0,j]+father[1,tail[1]]<=10 then begin writeln(father[0,j]+father[1,tail[1]]);halt;end

else begin writeln('NO ANSWER!');halt;end;

end;

procedure expand(p:longint);

var i,d:longint;

s:string;

begin

inc(head[p]);

s:=c[p,head[p]];

for i:=1 to k do

if pos(f[p,i].x,s)>0 then begin

inc(tail[p]);

father[p,tail[p]]:=father[p,head[p]]+1;

d:=pos(f[p,i].x,s);

c[p,tail[p]]:=s;

delete(c[p,tail[p]],d,length(f[p,i].x));

insert(f[p,i].y,c[p,tail[p]],d);

if chong(tail[p],p) then dec(tail[p]);

ok(p);

end;

end;

begin

assign(input,'input.in');

reset(input);

init;

max:=10;

fillchar(head,sizeof(head),0);

fillchar(c,sizeof(c),0);

tail[0]:=1;

tail[1]:=1;

c[0,1]:=a;

c[1,1]:=b;

repeat

if (head[1]<head[0]) and(tail[1]<tail[0])and(tail[1]<max) then expand(1);

if (head[0]<=head[1]) and(tail[0]<=tail[1])and(tail[0]<=max) then expand(0);

if (head[0]<=tail[0])and(tail[0]<=max) then expand(0);

if (head[1]<=tail[1])and(tail[1]<=max) then expand(1);

until (head[0]>tail[0])or(tail[0]>max)or(head[1]>tail[1])or(tail[1]>max);

writeln('NO ANSWER!');

close(input);

end.

#1 408534734@2013-10-25 00:57:00
回复 删除
我没看你的程序,不过我也错得一样,和可能是因为你在$A中查找$Ai时只找了第一个$Ai就退出了本次对$Ai的查找,其实$A后面还有个$Ai
#2 1170532871@2017-02-18 02:47:43
回复 删除
这题貌似是要改成双向宽搜
#3 1170532871@2017-02-18 02:48:00
回复 删除
我也是这样呢
#4 1170532871@2017-02-18 06:38:14
回复 删除
是的 确认双向宽搜
查看更多回复
提交回复