记录编号 |
14497 |
评测结果 |
AAAAAATTAA |
题目名称 |
[NOIP 2004]虫食算 |
最终得分 |
80 |
用户昵称 |
ReimBurSe. |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
2.725 s |
提交时间 |
2009-10-30 15:36:34 |
内存使用 |
0.11 MiB |
显示代码纯文本
Program alpha;
Type
sc=array [1..3,1..25] of integer;
Var
s,ss:sc;
n,i,j,k:integer;
s1:string;
temp,pp:array [0..24] of integer;
panduan:array [0..24] of boolean;
Procedure print;
Var i:integer;
Begin
for i:=1 to n do write(pp[i],' ');
writeln;
close(input);
close(output);
halt;
End;
Procedure aaa(i,j,jw:integer);
Var k,c,w,temp1:integer;
Begin
if i<>3 then begin
if pp[s[i,j]]<>-1 then begin
ss[i,j]:=pp[s[i,j]];
aaa(i+1,j,jw);
end
else begin
for k:=0 to (n-1) do begin
if panduan[k]=true then begin
ss[i,j]:=k;
pp[s[i,j]]:=k;
panduan[k]:=false;
aaa(i+1,j,jw);
panduan[k]:=true;
pp[s[i,j]]:=-1;
end;
end;
end;
end
else begin
if j=n then print
else begin
temp1:=ss[1,j]+ss[2,j]+jw;
c:=temp1 div n;
w:=temp1 mod n;
if pp[s[i,j]]<>-1 then begin
if pp[s[i,j]]=w then begin
ss[i,j]:=w;
aaa(1,j+1,c);
end;
end
else begin
if panduan[w]=true then begin
ss[i,j]:=w;
pp[s[i,j]]:=w;
panduan[w]:=false;
aaa(1,j+1,c);
pp[s[i,j]]:=-1;
panduan[w]:=true;
end;
end;
end;
end;
end;
Begin
assign(input,'alpha.in');
assign(output,'alpha.out');
reset(input);
rewrite(output);
readln(n);
readln(s1);
k:=n;
for j:=1 to n do begin
temp[j]:=ord(s1[j])-ord('A')+1;
s[1,k]:=temp[j];
k:=k-1;
end;
readln(s1);
k:=n;
for j:=1 to n do begin
temp[j]:=ord(s1[j])-ord('A')+1;
s[2,k]:=temp[j];
k:=k-1;
end;
readln(s1);
k:=n;
for j:=1 to n do begin
temp[j]:=ord(s1[j])-ord('A')+1;
s[3,k]:=temp[j];
k:=k-1;
end;
for i:=0 to n do pp[i]:=-1;
for i:=0 to n do panduan[i]:=true;
aaa(1,1,0);
End.