[Original question link]
Http://acm.pku.edu.cn/JudgeOnline/problem? Id = 2709
[Topic]
To configure N (3 <= n <= 12) colors and a certain amount of gray pigments, it can be seen that gray pigments can be obtained by mixing any three non-gray pigments with the same amount. The amount of pigments required for each color (including gray) is input, determine how many pigments are required (each pigment includes all colors except black, each color is 50 ml per bottle ).
[Solution ideas]
GreedyAlgorithm, The volume decreases by mL, and the required volume increases gradually, and the number of copies of the required color is obtained.
[Remarks]
Here, mixing is not necessarily a bottle-by-bottle mixture, but can be a mixture of any volume.
[SourceProgram]
[Code]
# Include <iostream>
# Include <algorithm>
# Include <string>
Using namespace STD;
Long colvol [20], remain [20];
Bool CMP (long a, long B) {return A> B ;}
Int main ()
{
Long colnum, gray, I, empty, in;
While (CIN> colnum, colnum)
{
For (I = 0; I <colnum; I ++) CIN> colvol [I];
Sort (colvol, colvol + colnum );
Cin> gray;
If (colvol [colNum-1] % 50) in = (colvol [colNum-1]/50 + 1) * 50;
Else In = colvol [colNum-1];
// The quantity to be added when the in is not black
For (I = 0; I <colnum; I ++) remain [I] = In-colvol [I]; // remain indicates the quantity of black colors that can be used for matching.
While (Gray) // if the required amount of Black is not 0, the loop continues.
{
Sort (remain, remain + colnum, CMP); // sort each time from high to low
If (! Remain [2]) // if the remaining color of the third digit has been used up, use another pigment.
{In + = 50; for (I = 0; I <colnum; I ++) remain [I] + = 50 ;}
Remain [0] --; remain [1] --; remain [2] --; gray --;
}
Cout <in/50 <Endl; // number of output bottles
}
Return 0;
}
[/Code]