水煮小小鱼
发表于 2017-5-27 14:52:43
BFS算法的Python实现
孤独的林
发表于 2017-6-12 17:59:28
学习
nlyh
发表于 2017-6-12 20:39:28
学习学习 看看代码
WelanceLee
发表于 2017-6-15 21:08:11
本帖最后由 WelanceLee 于 2017-6-15 21:10 编辑
def xdd(arr, r):
if r not in arr:
arr.append(r)
action = arr
return arr
start = (0, 0)
queue =
action = {}
index = 0
while True:
q = queue
if q == 2 or q == 2:
break
xdd(queue, (7, q))
xdd(queue, (0, q))
xdd(queue, (q, 0))
xdd(queue, (q, 11))
x = q + q
if x <= 7:
xdd(queue, (x, 0))
xdd(queue, (0, x))
if 7 < x < 11:
xdd(queue, (7, x - 7))
xdd(queue, (0, x))
if x >= 11:
xdd(queue, (x - 11, 11))
xdd(queue, (7, x - 7))
index += 1
solution = [(0,0)]
while q != (0, 0):
solution.insert(1, q)
q = action
for each in solution:
print(each)
没用pop,直接在queue里面看状态是不是走过
P先生
发表于 2017-6-26 09:43:28
qaz123765
发表于 2017-7-3 23:16:48
来看下程序
yhe0924
发表于 2017-8-19 22:00:07
学习下BFS 搞不懂头疼极了
Castieler
发表于 2017-8-22 14:04:19
1
joeyzhong
发表于 2017-10-20 02:37:28
感谢分享,真需要
聂路成
发表于 2017-10-20 15:08:05
学习
tianduan18
发表于 2017-10-22 22:18:12
求答案~
昨日已化成烟
发表于 2017-10-23 10:36:02
采用迭代判断进行计算吗?
兢兢
发表于 2017-10-24 21:01:12
上酒{:5_97:}
hszzjs
发表于 2017-11-21 10:11:00
学习学习!!
yyf900524
发表于 2017-12-11 10:51:28
回复看源码
mahaweilu
发表于 2018-1-9 17:58:55
nice
shigure_takimi
发表于 2018-1-16 15:57:49
{:5_91:}
JAY饭
发表于 2018-3-3 13:17:20
{:9_221:}这个题确实想不出广度探索法的需求,因为我试了一下都是直线型的思路,所以:
m,n = 7,11
visit = []
def move(a,b,m,n):
if a == 0:
if b == 0:
a += m
elif b != 0 and b != n:
a += m
else:
return None
elif a == m:
if b == 0:
t = n-b
if t <= a:
a -= t
b += t
else:
b += a
a = 0
elif b != 0 and b != n:
t = n-b
if t <= a:
a -= t
b +=t
elif t > a:
b += a
a = 0
elif a != 0 and a != m:
if b == n:
b=0
elif b == 0:
t = (n-b)
if t <= a:
a -= t
b +=t
elif t > a:
b += a
a = 0
print(a,b)
return a,b
a,b,c = 0,0,1
a1,b1,c1 =0,0,1
while c:
(a,b) = move(a,b,7,11)
if a ==2 or b ==2:
print('用了%d步'%c)
break
c += 1
while c1:
(a1,b1) = move(a1,b1,11,7)
if a1 ==2 or b1 ==2:
print('用了%d步'%c1)
break
c1 += 1
Hank_
发表于 2018-3-12 11:34:45
{:5_91:}
xiaozheasd123
发表于 2018-3-24 14:48:37
后来还开了个v客户管理客户