#P2729. [USACO3.2] 饲料调配 Feed Ratios
[USACO3.2] 饲料调配 Feed Ratios
Description
Given three sets of integers, each set represents the ratio of barley, oats, and wheat in one feed. Find a way to blend these three feeds to obtain a feed with ratio .
Write a program to find the solution that minimizes the total amount of the three feeds used. If it is impossible to obtain the target feed from these three feeds, output a single line containing the string NONE. “Minimum amount” means the sum of the amounts (integers) of the three feeds must be minimized.
For example, if we want to use feeds with ratios , , and to produce a feed with ratio , we can blend units of the first feed, unit of the second feed, and units of the third feed to obtain units of the target feed. This is because , , , and is exactly equal to .
Input Format
The first line contains three integers , indicating that the target feed has barley, oats, and wheat in the ratio .
The next three lines, the -th line contains three integers , indicating that the -th feed has barley, oats, and wheat in the ratio .
All integers in the input are between and inclusive, and in each line the three integers are not all .
Output Format
If the target feed can be obtained by blending the three feeds, output one line with integers. The first three integers represent the portions of the three feeds, and the fourth integer represents the number of portions of the target feed obtained. If there are multiple solutions, output the one with the smallest . If the target feed cannot be obtained from the three feeds, output a single line containing the string NONE. It is guaranteed that if a solution exists, the solution with the smallest is unique.
3 4 5
1 2 3
3 7 1
2 1 2
8 1 5 7
Hint
Translation from NOCOW. USACO Training Section 3.2.
Translated by ChatGPT 5
京公网安备 11011102002149号