码迷,mamicode.com
首页 > 其他好文 > 详细

0002_百钱买鸡

时间:2017-02-27 18:48:02      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:author   pytho   print   span   bsp   auth   python   style   odi   

百钱买鸡:公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,用100文钱买100只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱?

思路:设定公鸡,母鸡,小鸡各买x,y,z只,则满足下列条件:

    x+y+z=100;

    5x+3y+z/3=100;

 1 __author__ = qq593
 2 # /usr/bin/python
 3 # -*- coding:utf-8 -*-
 4 
 5 #x is the unknown number
 6 for y in range(1,33):
 7     for z in range(1,98):
 8         x =100-z-y
 9         if (0<x<20 and  x*5+y*3+z/3==100 and z%3==0):
10             print (x,y,z)
11 #z is the unknown number
12 for x in range(1, 20):
13     for y in range(1, 33):
14         z = 100 - x - y
15         if (z % 3 == 0) and (x * 5 + y * 3 + z / 3 == 100):
16             s = "gongji:%d;muji:%d;xiaoji:%d" % (x, y, z)
17             print (s)
18 #y is the unknown number
19 for x in range(1,20):
20     for z in range(98):
21         y=100-x-z
22         if (x*5+y*3+z/3==100 and z%3==0 and 0<y<33):
23             print (x,y,z)

 

0002_百钱买鸡

标签:author   pytho   print   span   bsp   auth   python   style   odi   

原文地址:http://www.cnblogs.com/elijahxb/p/6475493.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!