讨论 / 发个我的做法仅供bs
wyhbb163 2010-05-22 00:04:00
点我顶贴 收藏 删除
const

c:array [0..2,1..4] of integer=((3,-3,-1,0),(3,-3,1,0),(-3,3,-1,1));

var

hash:array[1..900000] of boolean;

f:array[1..100000] of string;

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

s,e,i,p1,p2,h,c1:longint;

t:char;

p,te:string;

begin

readln(p);

f[1]:=’123804765’;

d[1]:=0;

s:=1;

e:=1;

repeat

p1:=pos(’0’,f[s]);

c1:=p1 mod 3;

for i:=1 to 4 do begin

p2:=p1+c[c1,i];

if (p2>0) and (p2<10) then begin

te:=f[s];

t:=te[p2];

te[p2]:=te[p1];

te[p1]:=t;

val(te,h);

h:=h mod 99983;

if hash[h]=false then begin

hash[h]:=true;

e:=e+1;

f[e]:=te;

d[e]:=d[s]+1;

end;

if te=p then begin

writeln(d[e]);

halt;

end;

end;

end;

s:=s+1;

until s>e;

end.

#1 Jollwish@2008-08-14 06:23:00
回复 删除
你的什么意思?和哈希表有关吗?
#2 wyhbb163@2008-08-14 06:32:00
回复 删除
有点关系,用来判重
#3 Zx.MYS@2008-08-14 06:50:00
回复 删除
@_@最好写篇题解详解一下这做法……
#4 Jollwish@2008-08-14 06:55:00
回复 删除
同意,
#5 DarkMaster@2008-08-14 17:19:00
回复 删除
唉,LZ在BS数据弱呢,广搜都过了。。。
#6 xiaokeke@2008-08-14 18:42:00
回复 删除
果真bfs…………
#7 DarkMaster@2008-08-15 06:50:00
回复 删除
.........不会现在才发现吧-_-~.....
#8 L.Lawliet@2010-05-22 00:04:00
回复 删除
没见你写康托啊?怎么Hash?

查看更多回复
提交回复