UVA Problem - 102 solution ( Ecological Bin Packing )

www.ebatayon.com

#include 
#include 
#include 
using namespace std;
int main()
{
    int G[3],B[3],C[3];

    while(scanf("%d %d %d %d %d %d %d %d %d",&B[0],&G[0],&C[0],&B[1],&G[1],&C[1],&B[2],&G[2],&C[2]) != EOF)
    {
        int min = INT_MAX,temp;
        char ans[4];
        temp = G[0] + C[0] + B[1] + G[1] + B[2] + C[2];
        if(temp < min)
        {
            min = temp;
            strcpy(ans,"BCG");
        }
        temp = G[0] + C[0] + B[1] + C[1] + B[2] + G[2];
        if(temp < min)
        {
            min = temp;
            strcpy(ans,"BGC");
        }
        temp = B[0] + G[0] + C[1] + G[1] + C[2] + B[2];
        if(temp < min)
        {
            min = temp;
            strcpy(ans,"CBG");
        }
        temp = G[0] + B[0] + C[1] + B[1] + C[2] + G[2];
        if(temp < min)
        {
            min = temp;
            strcpy(ans,"CGB");
        }
        temp = B[0] + C[0] + G[1] + C[1] + B[2] + G[2];
        if(temp < min)
        {
            min = temp;
            strcpy(ans,"GBC");
        }
        temp = C[0] + B[0] + G[1] + B[1] + G[2] + C[2];
        if(temp < min)
        {
            min = temp;
            strcpy(ans,"GCB");
        }
        printf("%s %d\n",ans,min);
    }
    return 0;
}



Previous
Next Post »