#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numbers
import numpy
import math
'''
三个容器分别为12升、8升、5升,初始时12升容器盛满酒,就只能在三个容器中来回倾倒,如某容器中恰好6升就,则结束
3*2维数组:三个二维数组表示三个容器;二维数组第一个数字表示容器大小,第二数字表示当前容器中的酒量
结束条件:前两个二维数组中第二个数字为6
倒酒的动作:两个数组A,B之间,第一个向第二个倒酒
B[1]=B[0]或A[1]=0不操作
若A[1]+B[1]>=B[0],则A[1]=A[1]+B[1]-B[0],B[1]=B[0]
若B[0]>A[1]+B[1],则B[1]=A[1]+B[1],A[1]=0
到酒后的动作:记录三个容器中的酒量到队列:若任意一个等于6则打印返回;
若队列中与当结果不存在重复,则继续下一个倒酒动作
每个状态有六种倒酒操作:1-》2 ,1-》3,2-》3,2-》1,3-》1,3->2
'''
#initstatus=[[12,2],[8,5],[5,5]]
class purewine(object):
def __init__(self):
pass
def purewine(self,A,B,a,b):
if a + b >= B:
a = a + b - B
b = B
else:
b = a + b
a = 0
return A,B,a,b
def judge(self,A,B,C,a,b,c,t='',r=0):
restr=str(a)+str(b)+str(c)
if a==r or b==r or c==r:
t=t+','+restr
print(t)
return True
else:
if t.count(restr)<1:
t = t + ',' + restr
self.dynamictree(A,B,C,a,b,c,t,r)
def dynamictree(self,A,B,C,a,b,c,t='',r=0):
j,k,m,n=self.purewine(A,B,a,b,)
self.judge(j,k,C,m,n,c,t,r)
j,k,m,n = self.purewine(A, C, a, c)
self.judge(j, B, k, m, b, n, t, r)
j, k, m, n = self.purewine(B, C, b, c)
self.judge(A, j, k, a, m, n, t, r)
j, k, m, n = self.purewine(C, B, c, b)
self.judge(A, k, j, a, n, m, t, r)
j, k, m, n = self.purewine(C, A, c, a)
self.judge(k, B, j, n, b, m, t, r)
j, k, m, n = self.purewine(B, A, b, a)
self.judge(k, j, C, n, m, c, t, r)
wins=purewine()
wins.dynamictree(12,8,5,12,0,0,'1200',6)
输出:
1200,480,084,804,840,345,381,1101,1110,615
1200,480,435,075,084,804,840,345,381,1101,1110,615
1200,480,435,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,615
1200,480,435,075,570,525,1020,1002,705,750,255,282,084,804,840,345,381,1101,1110,615
1200,480,435,075,570,525,705,750,255,282,084,804,840,345,381,1101,1110,615
1200,480,435,075,705,750,255,282,084,804,840,345,381,1101,1110,615
1200,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,480,435,930,903,183,165
1200,480,435,930,903,705,075,084,804,840,345,381,1101,1110,615
1200,480,435,930,903,705,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,615
1200,480,435,930,903,705,750,255,075,084,804,840,345,381,1101,1110,615
1200,480,435,930,903,705,750,255,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,615
1200,480,435,930,903,705,750,255,282,084,804,840,345,381,1101,1110,615
1200,480,435,930,903,705,750,255,282,1002,1020,525,075,084,804,840,345,381,1101,1110,615
1200,480,435,930,903,705,750,255,282,1002,1020,525,570,075,084,804,840,345,381,1101,1110,615
1200,480,435,705,075,084,804,840,345,381,1101,1110,615
1200,480,435,705,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,615
1200,480,435,705,750,255,075,084,804,840,345,381,1101,1110,615
1200,480,435,705,750,255,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,615
1200,480,435,705,750,255,282,084,804,840,345,381,1101,1110,615
1200,480,435,705,750,255,282,1002,1020,525,075,084,804,840,345,381,1101,1110,615
1200,480,435,705,750,255,282,1002,1020,525,570,075,084,804,840,345,381,1101,1110,615
1200,705,075,084,480,435,930,903,183,165
1200,705,075,084,804,840,480,435,930,903,183,165
1200,705,075,084,804,840,345,381,480,435,930,903,183,165
1200,705,075,084,804,840,345,381,1101,1110,480,435,930,903,183,165
1200,705,075,084,804,840,345,381,1101,1110,615
1200,705,075,570,480,084,804,840,345,381,1101,1110,615
1200,705,075,570,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,075,570,480,435,930,903,183,165
1200,705,075,570,525,1020,480,084,804,840,345,381,1101,1110,615
1200,705,075,570,525,1020,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,075,570,525,1020,480,435,930,903,183,165
1200,705,075,570,525,1020,1002,282,084,480,435,930,903,183,165
1200,705,075,570,525,1020,1002,282,084,804,840,480,435,930,903,183,165
1200,705,075,570,525,1020,1002,282,084,804,840,345,381,480,435,930,903,183,165
1200,705,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,480,435,930,903,183,165
1200,705,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,615
1200,705,075,570,525,1020,1002,282,255,750,480,084,804,840,345,381,1101,1110,615
1200,705,075,570,525,1020,1002,282,255,750,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,075,570,525,1020,1002,282,255,750,480,435,930,903,183,165
1200,705,075,570,525,1020,1002,282,480,084,804,840,345,381,1101,1110,615
1200,705,075,570,525,1020,1002,282,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,075,570,525,1020,1002,282,480,435,930,903,183,165
1200,705,750,480,084,804,840,345,381,1101,1110,615
1200,705,750,480,435,075,084,804,840,345,381,1101,1110,615
1200,705,750,480,435,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,615
1200,705,750,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,750,480,435,930,903,183,165
1200,705,750,255,075,084,480,435,930,903,183,165
1200,705,750,255,075,084,804,840,480,435,930,903,183,165
1200,705,750,255,075,084,804,840,345,381,480,435,930,903,183,165
1200,705,750,255,075,084,804,840,345,381,1101,1110,480,435,930,903,183,165
1200,705,750,255,075,084,804,840,345,381,1101,1110,615
1200,705,750,255,075,570,480,084,804,840,345,381,1101,1110,615
1200,705,750,255,075,570,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,750,255,075,570,480,435,930,903,183,165
1200,705,750,255,075,570,525,1020,480,084,804,840,345,381,1101,1110,615
1200,705,750,255,075,570,525,1020,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,750,255,075,570,525,1020,480,435,930,903,183,165
1200,705,750,255,075,570,525,1020,1002,282,084,480,435,930,903,183,165
1200,705,750,255,075,570,525,1020,1002,282,084,804,840,480,435,930,903,183,165
1200,705,750,255,075,570,525,1020,1002,282,084,804,840,345,381,480,435,930,903,183,165
1200,705,750,255,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,480,435,930,903,183,165
1200,705,750,255,075,570,525,1020,1002,282,084,804,840,345,381,1101,1110,615
1200,705,750,255,075,570,525,1020,1002,282,480,084,804,840,345,381,1101,1110,615
1200,705,750,255,075,570,525,1020,1002,282,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,750,255,075,570,525,1020,1002,282,480,435,930,903,183,165
1200,705,750,255,282,084,075,570,480,435,930,903,183,165
1200,705,750,255,282,084,075,570,525,1020,480,435,930,903,183,165
1200,705,750,255,282,084,480,435,930,903,183,165
1200,705,750,255,282,084,804,840,480,435,930,903,183,165
1200,705,750,255,282,084,804,840,345,075,570,480,435,930,903,183,165
1200,705,750,255,282,084,804,840,345,075,570,525,1020,480,435,930,903,183,165
1200,705,750,255,282,084,804,840,345,381,480,435,930,903,183,165
1200,705,750,255,282,084,804,840,345,381,1101,1110,480,435,930,903,183,165
1200,705,750,255,282,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,480,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,480,435,075,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,480,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,1002,1020,480,435,075,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,1002,1020,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,1002,1020,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,075,084,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,075,084,804,840,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,075,084,804,840,345,381,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,075,084,804,840,345,381,1101,1110,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,075,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,1002,1020,525,075,570,480,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,1002,1020,525,075,570,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,1002,1020,525,075,570,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,570,480,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,1002,1020,525,570,480,435,075,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,1002,1020,525,570,480,435,930,903,183,084,804,840,345,381,1101,1110,615
1200,705,750,255,282,1002,1020,525,570,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,570,075,084,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,570,075,084,804,840,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,570,075,084,804,840,345,381,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,570,075,084,804,840,345,381,1101,1110,480,435,930,903,183,165
1200,705,750,255,282,1002,1020,525,570,075,084,804,840,345,381,1101,1110,615