Home > other >  PYTHON exhaustive method for help
PYTHON exhaustive method for help

Time:09-20

A length of 235 m of the material, need cut growth degree of 19 m and 23 m short, programming design best interception schemes, namely beg two short expected each how many root, cut into the rest of the material at least? (plan could have a variety of, can a can,)
5 6 2 [sample output]

CodePudding user response:

Go the wrong area brothers

CodePudding user response:

Go the wrong area brothers

CodePudding user response:

 
23 # 19 + x * * y + z=235
If __name__=="__main__ ':
Total=235 # take common multiple of x and y (such as 437) will have more than one result
Unit_x=19
23 unit_y=
List_initial=[]
For the x in the range (total//unit_x + 1) :
For y in range (total//unit_y + 1) :
If x + y * * unit_x unit_y & lt;=total:
Z=total - x * unit_x - y * unit_y
List_initial. Append ((x, y, z))
# print (f 'x * * {unit_y} {unit_x} + y + z={total} : x={x}, y={} y, z={} z')

List_sortz=sorted (list_initial, key=lambda x: x [2]) # sort by z
Min_z=list_sortz [0] [2]
For the row in list_sortz:
If min_z & lt; The row [2] :
Break
Print (row)
# print (f 'x={row [0]}, y={row [1]}, z={row [2]}')
  • Related