用两个量筒得出一定加仑水的问题
来源:互联网 发布:开源微商城源码 编辑:程序博客网 时间:2024/05/16 19:07
#一个a加仑的量筒,一个b加仑量筒,得到c加仑水
class node(object): def __init__(self): self.cura = 0 self.curb = 0 self.x = [] self.pairs = [[0,0]]def append_node(wlist,tempa,tempb,i,old): new_node = node() new_node.cura = tempa new_node.curb = tempb new_node.x = old.x[:] new_node.x.append(i) new_node.pairs = old.pairs[:] new_node.pairs.append([tempa,tempb]) wlist.append(new_node)def water(a,b,c): root = node() wlist = [] wlist.append(root) while(len(wlist) > 0): old = wlist.pop(0) #print old.pairs if old.cura==c or old.curb==c: print old.pairs return i = 1 while i <= 5: if i == 1: tempa = a tempb = old.curb if [tempa,tempb] in old.pairs: i += 1 continue append_node(wlist,tempa,tempb,i,old) if i == 2: tempa = 0 tempb = old.curb if [tempa,tempb] in old.pairs: i += 1 continue append_node(wlist,tempa,tempb,i,old) if i == 3: tempa = old.cura tempb = b if [tempa,tempb] in old.pairs: i += 1 continue append_node(wlist,tempa,tempb,i,old) if i == 4: tempa = old.cura tempb = 0 if [tempa,tempb] in old.pairs: i += 1 continue append_node(wlist,tempa,tempb,i,old) if i == 5: left_b = b - old.curb if old.cura <= left_b: tempa = 0 tempb = old.curb + old.cura else: tempa = old.cura - left_b tempb = b if [tempa,tempb] in old.pairs: i += 1 continue append_node(wlist,tempa,tempb,i,old) if i == 6: left_a = a - old.cura if old.curb <= left_a: tempa = old.cura +old.curb tempb = 0 else: tempa = a tempb = old.curb -left_a if [tempa,tempb] in old.pairs: i += 1 continue append_node(wlist,tempa,tempb,i,old) i += 1
0 0
- 用两个量筒得出一定加仑水的问题
- 量筒量水问题,一个五升的量筒,一个七升的量筒,怎么得到六升的水?
- 量筒量水问题1--一个盛满水的池子,有一个6升的量筒,一个5升的量筒,怎样量出3升水?
- 量筒量水问题2--如果你有足量的水,一个3升的和一个5升的量筒,你如何准确称出4升的水
- 输入两个日期得出相差的月份
- js两个时间的计算得出最后的天数
- 职场新人请教问题一定不能犯的两个错误
- 黑加仑
- 关于局部变量问题得出的发现与反思
- php判断比较两个数组中的数据(得出删除的,和新增的)
- 如何得出两个日期间各个季、月、周的开始日期、结束日期?
- 使用TimeDifference,实现两个时间变量的相减,得出秒间隔
- 不用if-else和比较运算符,得出两个数中较大的那个数
- java 中 equals() 相等的两个对象,hashcode() 一定相等
- java 中 equals() 相等的两个对象,hashcode() 一定相等
- 满足一定要求的排列组合问题
- 选定好一定个方向的问题
- java得出两个日期之间所有日期
- teamview 无法捕获界面
- [Ruby] Install vagrant and virtualbox-4.2 on ububtu
- 天涯明月刀 题三
- ARM寄存器简介
- 天涯明月刀 题四
- 用两个量筒得出一定加仑水的问题
- a --> java面试知识点相关
- 中戏新生军训美女撞脸 中戏校花大盘点
- 当迷茫在大学泛滥成灾 -- 李开复
- LRU Cache设计
- python3.4.1作品查找指定路径下的文件
- C# 检测邮箱和URL是否正确
- Ubuntu下伪分布式模式Hadoop的安装及配置
- 按钮提交先进行判断再执行post的方法