百练 / 2019计算机学科夏令营上机考试 C:Hopscotch

百练 / 2019计算机学科夏令营上机考试 C:Hopscotch

# 百练 / 2019计算机学科夏令营上机考试 C:Hopscotch
# http://bailian.openjudge.cn/xly2019/C/
# Author:NitrogenousFish
# github:https://github.com/NITROGENousFish/
class Node:
    def __init__(self,val,path):
        self.path = path
        self.val = val

def main():
    num_list = []
    while(1):
        input_thing = list(map(int,input().split()))
        if input_thing[0] == 0 and input_thing[1] == 0:
            break
        else:
            num_list.append(input_thing)
            
    for number_list in num_list:
        start = number_list[0]
        end = number_list[1]
        queue = []
        rootnode = Node(start,"")
        queue.append(rootnode)
        while len(queue):
            currentnode = queue.pop(0)
            leftnode = Node(currentnode.val*3,currentnode.path+"H")
            queue.append(leftnode)
            if currentnode.val//2!=0:
                rightnode = Node(currentnode.val//2,currentnode.path+"O") 
                queue.append(rightnode)
            if currentnode.val == end:
                print(len(currentnode.path))
                print(currentnode.path)
                return
            
if __name__ == "__main__":
    main()
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值