本文主要是介绍十、田忌赛马策略:故意让最弱的马输给对方最强的马,然后其他两匹马设法取胜。 设有三匹马,能力值分别为10,20,30。输入任意三匹马的能力值,若这三匹马有可能取胜,输出能取胜的三场对阵表,若无论如何,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
horse1 = [10,20,30]h1=int(input("请输入第1批马子的能力值"))
h2=int(input("请输入第2批马子的能力值"))
h3=int(input("请输入第3批马子的能力值"))
h=[h1,h2,h3]#30 30 *
if (h[1]==horse1[2] and h[2]==horse1[2]):print(str(h[1]) + 'vs' + str(horse1[0]))print(str(h[2]) + 'vs' + str(horse1[1]))print(str(h[0]) + 'vs' + str(horse1[2]))
elif (h[0]==horse1[2] and h[1]==horse1[2]):print(str(h[0]) + 'vs' + str(horse1[0]))print(str(h[1]) + 'vs' + str(horse1[1]))print(str(h[2]) + 'vs' + str(horse1[2]))
elif (h[0] == horse1[2] and h[2] == horse1[2]):print(str(h[0]) + 'vs' + str(horse1[0]))print(str(h[2]) + 'vs' + str(horse1[1]))print(str(h[1]) + 'vs' + str(horse1[2]))
#20 30 *
elif (h[0]==horse1[1] and h[1]==horse1[2]):print(str(h[0]) + 'vs' + str(horse1[0]))print(str(h[1]) + 'vs' + str(horse1[1]))print(str(h[2]) + 'vs' + str(horse1[2]))
elif (h[0]==horse1[2] and h[1]==horse1[1]):print(str(h[0]) + 'vs' + str(horse1[1]))print(str(h[1]) + 'vs' + str(horse1[0]))print(str(h[2]) + 'vs' + str(horse1[2]))
elif (h[0] == horse1[2] and h[2] == horse1[1]):print(str(h[0]) + 'vs' + str(horse1[1]))print(str(h[1]) + 'vs' + str(horse1[2]))print(str(h[2]) + 'vs' + str(horse1[0]))
elif (h[0] == horse1[1] and h[2] == horse1[2]):print(str(h[0]) + 'vs' + str(horse1[0]))print(str(h[1]) + 'vs' + str(horse1[2]))print(str(h[2]) + 'vs' + str(horse1[1]))
elif (h[1] == horse1[2] and h[2] == horse1[1]):print(str(h[0]) + 'vs' + str(horse1[2]))print(str(h[1]) + 'vs' + str(horse1[0]))print(str(h[2]) + 'vs' + str(horse1[1]))
elif (h[1] == horse1[1] and h[2] == horse1[2]):print(str(h[0]) + 'vs' + str(horse1[2]))print(str(h[1]) + 'vs' + str(horse1[1]))print(str(h[2]) + 'vs' + str(horse1[0]))else:print("无法取胜")
这篇关于十、田忌赛马策略:故意让最弱的马输给对方最强的马,然后其他两匹马设法取胜。 设有三匹马,能力值分别为10,20,30。输入任意三匹马的能力值,若这三匹马有可能取胜,输出能取胜的三场对阵表,若无论如何的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!