讨论 / 求大神
wxz 2013-08-12 21:48:00
点我顶贴 收藏 删除
program t1;

const sz='123804765';

var x:array[1..9,0..4]of longint;

i,j,n,t:longint;

s:string;

f:array[1..87654321]of boolean;

a,l:array[1..2000000]of longint;

s1:array[1..2000000]of string[9];

procedure dabiao;

begin

x[1,0]:=2;x[1,1]:=2;x[1,2]:=4;

x[2,0]:=3;x[2,1]:=1;x[2,2]:=3;x[2,3]:=5;

x[3,0]:=2;x[3,1]:=2;x[3,2]:=6;

x[7,0]:=2;x[7,1]:=4;x[7,2]:=8;

x[9,0]:=2;x[9,1]:=6;x[9,2]:=8;

x[4,0]:=3;x[4,1]:=1;x[4,2]:=5;x[4,3]:=7;

x[6,0]:=3;x[6,1]:=3;x[6,2]:=5;x[6,3]:=9;

x[8,0]:=3;x[8,1]:=5;x[8,2]:=7;x[8,3]:=9;

x[5,0]:=4;x[5,1]:=2;x[5,2]:=4;x[5,3]:=6;x[5,4]:=8;

end;

procedure wxz;

var i,h,t,r,d:longint;temp:char;s2:string;

begin

h:=1;t:=1;

while h<=t do

begin

for i:=1 to x[a[h],0] do

begin

s2:=s1[h];

temp:=s2[x[a[h],i]];

s2[x[a[h],i]]:='0';

s2[a[h]]:=temp;

val(s2,d);

d:=d div 10;

if f[d]=true then begin

inc(t);

a[t]:=x[a[h],i];

l[t]:=l[h]+1;

s1[t]:=s2;

if s1[t]=sz then begin

writeln(l[t]);

halt;

end;

f[d]:=false;

end;

end;

inc(h);

end;

end;

begin

readln(s);

dabiao;

for i:=1 to 9 do

if s[i]='0' then a[1]:=i;

s1[1]:=s;l[1]:=0;val(s,t);

t:=t div 10;

fillchar(f,sizeof(f),true);

f[t]:=false;

wxz;

end.

为什么在vijos过了,在这里就80(一组超时一组WA),谁能帮看看错哪?

查看更多回复
提交回复