Wednesday, March 2, 2016

UVa 102 Solution - Ecological Bin Packing

#include <bits/stdc++.h>
#define LL  long long
#define REP(i,n) for(int i=0;i<n;i++)
#define pri(a) cout<<a<<endl
#define prii(a,b) cout<<a<<" "<<b<<endl
#define priii(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define hi printf("Hello World\n");
using namespace std;

const int INF = 1<<29;
const int MX  = 1e5+10;

//** we've 6 combinations in total.. manually think of all possible comb and their costs 

int main()
{
    LL b1,g1,c1,b2,g2,c2,b3,g3,c3,b[10];

    string cmb[6]={"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};

    while(cin>>b1>>g1>>c1>>b2>>g2>>c2>>b3>>g3>>c3)
    {
        b[0] =  b2+b3 + c1+c3 + g1+g2;  ///BCG
        b[1] =  b2+b3 + g1+g3 + c1+c2;  ///BGC
        b[2] =  c2+c3 + b1+b3 + g1+g2;  ///CBG
        b[3] =  c2+c3 + g1+g3 + b1+b2;  ///CGB
        b[4] =  g2+g3 + b1+b3 + c1+c2;  ///GBC
        b[5] =  g2+g3 + c1+c3 + b1+b2;  ///GCB

        LL mn = INF;

        REP(i,6){
            mn=min(mn,b[i]);
        }
        REP(i,6){
            if(mn==b[i]) {prii(cmb[i],b[i]); break;}
        }
    }
    return 0;
}

No comments:

Post a Comment