本帖最后由 qaz123765 于 2017-7-6 00:18 编辑
遍历了,但是算不出来,只能4*3算算了#red:0 blue:1 white:2. 4*3
begin=(2,0,1,1,0,0,1,1,0,0,1,1)
end=(2,1,0,1,1,0,1,0,0,1,0,1)
move=[(0,-1),(0,1),(1,0),(-1,0)]
step={}
st=
s=st.pop()
sss=
def check(x):
if tuple(x) not in sss:
st.append(tuple(x))
step=s
sss.append(tuple(x))
def twol(y):
global i
for j in range(12):
if y==2:
i=j
while s!=begin:
a,b,c,d=list(s),list(s),list(s),list(s)
for mo in move:
if mo==(0,-1):
twol(a)
if a not in a:
a,a=a,a
check(a)
elif mo==(0,1):
twol(b)
if b not in b:
b,b=b,b
check(b)
elif mo==(1,0):
twol(c)
if c not in c:
c,c=c,c
check(c)
elif mo==(-1,0):
twol(d)
if d not in d:
d,d=d,d
check(d)
s=st.pop(0)
if len(st)==0:
print("no solution!")
break
else:
sa=begin
print("start!!")
print(sa)
while sa!=end:
sa=step
print(sa)
楼主这个怎么收敛的,什么思路,全都加到列表里面貌似要很久
回复看代码
没学过算法,真是看不懂。
为什么字符串的处理速度这么快~
{:7_130:}
{:5_94:}
已收藏,这个跟中国的华容道很相似,准备什么时候写一个解决华容道的程序
{:5_97:}
听说学习有鱼币。。
想看
python实现的数据结构里图的广度优先遍历和深度优先遍历?
{:5_90:}
{:10_266:}gg
学习
大佬
马克
{:5_102:}