python应用-解决现实应用题

   公鸡5元1只,母鸡3元1只,小鸡一元3只,100元买100只鸡,三种鸡各多少只 x+y+z=100 5*x+3*y+z//3=100 z%3==0 穷举法-穷尽所有的可能性找到真正的答案

   

for x in range (21):
    for y in range(34):
        for z in range (0,100,3):
            if x+y+z==100 and 5*x+3*y+z//3==100 :
                print (x,y,z)

for x in range (21):
    for y in range(34):
        z=100-x-y
        if 5*x+3*y+z//3==100  and z%3==0:
             print (x,y,z)
结果:
0 25 75
4 18 78
8 11 81
12 4 84
0 25 75
4 18 78
8 11 81
12 4 84

  

posted @ 2018-03-11 22:25  圆柱模板  阅读(338)  评论(0编辑  收藏  举报