记录编号 |
3373 |
评测结果 |
AAAATAAT |
题目名称 |
[NOIP 2002]字串变换 |
最终得分 |
75 |
用户昵称 |
辨机ZN |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
2.009 s |
提交时间 |
2008-10-06 19:59:06 |
内存使用 |
95.33 MiB |
显示代码纯文本
program ex(f1,f2);
type
zn=array [1..7,1..2] of string;
hu=array [1..20000] of string;
iu=array [1..350000] of string;
var
a:zn; i,j,k,l,m,n,p,head,tail,step,tou,wei,l4:integer;
f1,f2:text; flag,flag2:boolean;
start,answer,s:string; c,c2:hu; tree:iu;
procedure shuchu(u:integer);
begin
writeln(f2,u);
close(f1);
close(f2);
halt;
end;
procedure insert(xx:string);
var
p,i,j,k:integer; flag:boolean;
begin
p:=1; flag:=true;
while flag do
begin
if xx<tree[p] then
begin
p:=p*2;
if tree[p]='' then begin
tree[p]:=xx;
c[wei]:=xx;
exit;
end;
end
else
if xx>tree[p] then
begin
p:=p*2+1;
if tree[p]='' then begin
tree[p]:=xx;
c[wei]:=xx;
exit;
end;
end
else
if xx=tree[p] then begin dec(wei); exit; end;
end;
end;
procedure chuli;
var
st,s2,se,s3,s4:string;
i,j,m,k,q,k2:integer;
flag:boolean;
begin
inc(step);
for q:=head to tail do
begin
s2:=c[q];
for i:=1 to n do
begin
st:=a[i,1]; se:=a[i,2];
m:=pos(st,s2);
if m>0 then
begin
inc(wei);
s4:=copy(s2,1,m-1)+se+copy(s2,m+length(st),length(s2));
insert(s4);
if c[wei]=answer then shuchu(step);
end;
{pan duan chong fu}
j:=0; flag:=true; k2:=m; k:=m; s3:=s2; l4:=length(st);
while flag do
begin
j:=j+l4;
delete(s3,k2,j);
k2:=pos(st,s3); k:=k2;
if k>0 then
begin
k:=k+j;
inc(wei);
s4:=copy(s2,1,k-1)+se+copy(s2,k+length(st),length(s2));
insert(s4);
if c[wei]=answer then shuchu(step);
end
else
flag:=false;
end;
end;
end;
end;
begin
assign(f1,'string.in'); reset(f1);
assign(f2,'string.out'); rewrite(f2);
readln(f1,s);
start:=copy(s,1,pos(' ',s)-1);
answer:=copy(s,pos(' ',s)+1,length(s));
n:=0;
while not(eof(f1)) do
begin
readln(f1,s);
inc(n);
a[n,1]:=copy(s,1,pos(' ',s)-1);
a[n,2]:=copy(s,pos(' ',s)+1,length(s));
end;
head:=1; tail:=1;
tou:=1; wei:=1;
c[1]:=start;
tree[1]:=c[1];
for i:=1 to 10 do
begin
tou:=head; tail:=wei;
chuli;
head:=tail+1;
end;
writeln(f2,'NO ANSWER!');
close(f1);
close(f2);
end.