P先生 发表于 2017-6-26 09:40:09

P先生 发表于 2017-6-26 09:42:45

qaz123765 发表于 2017-7-3 12:56:05

本帖最后由 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)
            

qaz123765 发表于 2017-7-3 22:48:08

楼主这个怎么收敛的,什么思路,全都加到列表里面貌似要很久

yyf900524 发表于 2017-12-11 10:27:19

回复看代码

shigure_takimi 发表于 2017-12-11 10:50:58

没学过算法,真是看不懂。

JAY饭 发表于 2018-3-2 17:21:43

为什么字符串的处理速度这么快~

来钓鱼 发表于 2018-3-2 21:15:49

{:7_130:}

wenweno 发表于 2018-3-17 16:18:25

{:5_94:}

Chase_Kas 发表于 2018-3-19 11:04:52

已收藏,这个跟中国的华容道很相似,准备什么时候写一个解决华容道的程序

小明吖 发表于 2018-3-19 16:43:16

{:5_97:}

阿bang 发表于 2018-3-19 16:55:08

听说学习有鱼币。。

晓屁屁 发表于 2018-3-19 17:44:09

想看

土间埋 发表于 2018-3-19 17:50:19

python实现的数据结构里图的广度优先遍历和深度优先遍历?

会飞的加菲猫 发表于 2018-3-19 19:59:00

{:5_90:}

Pufffish 发表于 2018-6-22 17:41:39

{:10_266:}gg

粤语猫 发表于 2018-11-20 11:15:59

学习

夏日浅陌 发表于 2018-12-6 10:43:00

大佬

littlebozi 发表于 2019-1-16 15:39:24

马克

九九八十一 发表于 2019-2-9 17:31:44

{:5_102:}
页: 1 [2] 3
查看完整版本: python小练习(064):探索法(广度优先搜索)不到40行代码求解拼图游戏的最优路径