Home > Back-end >  Of new inquire.. The money to buy the best chicken
Of new inquire.. The money to buy the best chicken

Time:11-04

Refer to as shown in figure,,,,,,,,,,

CodePudding user response:

What you mean? Money is a fixed value, the single buy rooster just 50, after buying a X hens can only buy 50-1.5 X cock

CodePudding user response:

The money to buy chicken, identified as 100 money to buy the 100 chickens, three chicken each to buy a few, not more not less, hey hey

CodePudding user response:


Single buy the cock up 50, bought after I hen, a cock only buy 50-1.5 I only,

The fastest algorithm should be:

A hen, rooster, chicken respectively the I, j, k
Is:
I + j + k=100 -- -- -- -- -- -- -- -- (1)
3 I + 2 j + 0.5 k=100 -- -- -- -- -- -- -- - (2)
(2) type * 2 - (1) type: 5 I + 3 j=100 -- -- -- -- -- - (3)
From (3) type, I=20-3 j/5
To ensure that the I, j positive integer, so
Must be in multiples of 5 j (guarantee aliquot),
From (3) type j=33 + (1-5 I)/3
I minimum value=2 (guarantee (1-5 I)/3 is an integer)
J a maximum of 30 (I=2)

So the fastest algorithm should be:
For j=0 to 30 step 5
{
I=20 - j div (3 * 5)
K=100 - I - j
Print the I, j, k
}
end

CodePudding user response:

Mathematical method,
If all buy chicken, chicken need 50 money, a chicken in a hen, need to spend more money, 2.5 is 20 chickens in 20 after the hen just the money in the chicken, namely 0 r + 20 hen + 80 chickens for a solution,
Time considering the cock, in 100 chickens, choose x the chicken in to the cock, the remaining 50-1.5 x, then the chicken in to the hen, you will need to change (50-1.5 x)/2.5 only, so the 500-15 x need can be divided exactly by 25, it takes only five multiples of the 0 x,5,10,15,20,25,30, every x corresponding to a set of solution,
  • Related