// One-star problem
// Problem UVA102 Ecological Bin Packing
/*
This program is written by
Prof. Chua-Huang Huang
Department of Information Engineering and Computer Science
Feng Chia University
Taichung, Taiwan
Disclaimer:
The programming problem is downloaded from UVa Online Judge (https://uva.onlinejudge.org/).
The program solution is provided for helping students to prepare Collegiate Programming
Examination (CPE). The author does not guarantee the program is completely correct to pass
UVa Online Judge platform or CPE examination platform.
This program is not intended for a student to copy only. He/She should practice the
programming problem himself/herself. Only use the program solution as a reference.
The author is not responsible if the program causes any damage of your computer or
personal properties.
No commercial use of this program is allowed without the author's written permission.
*/
#include
#include
int main(void) {
int bin[3][3]; // The number of colored bottles in three recycle bins.
// The possible combinations of BGC are the following six cases in B C G alphabetical order.
// 0: Brwon, 1: Green, 2: Clear.
int permutation[6][3] = {{0, 2, 1}, {0, 1, 2}, {2, 0, 1}, {2, 1, 0}, {1, 0, 2}, {1, 2, 0}};
int moves, min;
int order, choice, i, j;
while (scanf("%d %d %d %d %d %d %d %d %d", // Input the number of colored bottles in three recycle bins.
&bin[0][0], &bin[0][1], &bin[0][2],
&bin[1][0], &bin[1][1], &bin[1][2],
&bin[2][0], &bin[2][1], &bin[2][2])==9) {
// Initially, set the minimum moves equals to the total number of bottles.
min = 0;
for (i=0; i<3; i++)
for (j=0; j<3; j++) min += bin[i][j];
// For the six orders of colored bottles, each order computes the number of moves.
for (order=0; order<6; order++) {
moves = 0;
for (i=0; i<3; i++) // Variable i denotes the number of recycle bin.
for (j=0; j<3; j++) { // Variable j denotes the color of bottles in bin i.
// If the color of bottles differs from the color of the bin, the bottles are moved.
if (permutation[order][i]!=j) moves += bin[i][j];
}
// If the number of moves is less than min, this color order is chosen.
if (moves